Skip to content

Commit 45693e2

Browse files
authored
Fix potential truncated chain spec stdout (#158)
* Read from chain spec json file * put chain spec json to tmp dir
1 parent 2bf6d50 commit 45693e2

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,20 @@ const stripChainspecJsonName = (chain: string) => {
7878
* @param chain
7979
*/
8080
const getChainspec = (image: string, chain: string) => {
81-
let res;
81+
const outputChainSpec = `${shell.tempdir()}/${chain}-${new Date().toISOString().slice(0, 10)}.json`;
8282
if (chain.endsWith('.json')) {
83-
res = exec(
84-
`docker run -v $(pwd)/${chain}:/${chain} --rm ${image} build-spec --chain=/${chain} --disable-default-bootnode`
83+
exec(
84+
`docker run -v $(pwd)/${chain}:/${chain} --rm ${image} build-spec --chain=/${chain} --disable-default-bootnode > ${outputChainSpec}`
8585
);
8686
} else {
87-
res = exec(`docker run --rm ${image} build-spec --chain=${chain} --disable-default-bootnode`);
87+
exec(`docker run --rm ${image} build-spec --chain=${chain} --disable-default-bootnode > ${outputChainSpec}`);
8888
}
8989

9090
let spec;
9191

9292
try {
93-
spec = JSON.parse(res.stdout);
93+
spec = JSON.parse(fs.readFileSync(outputChainSpec).toString());
94+
fs.unlinkSync(outputChainSpec);
9495
} catch (e) {
9596
return fatal('build spec failed', e);
9697
}

0 commit comments

Comments
 (0)