Skip to content

Commit

Permalink
Fix potential truncated chain spec stdout (#158)
Browse files Browse the repository at this point in the history
* Read from chain spec json file

* put chain spec json to tmp dir
  • Loading branch information
Kailai-Wang authored Aug 31, 2023
1 parent 2bf6d50 commit 45693e2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,20 @@ const stripChainspecJsonName = (chain: string) => {
* @param chain
*/
const getChainspec = (image: string, chain: string) => {
let res;
const outputChainSpec = `${shell.tempdir()}/${chain}-${new Date().toISOString().slice(0, 10)}.json`;
if (chain.endsWith('.json')) {
res = exec(
`docker run -v $(pwd)/${chain}:/${chain} --rm ${image} build-spec --chain=/${chain} --disable-default-bootnode`
exec(
`docker run -v $(pwd)/${chain}:/${chain} --rm ${image} build-spec --chain=/${chain} --disable-default-bootnode > ${outputChainSpec}`
);
} else {
res = exec(`docker run --rm ${image} build-spec --chain=${chain} --disable-default-bootnode`);
exec(`docker run --rm ${image} build-spec --chain=${chain} --disable-default-bootnode > ${outputChainSpec}`);
}

let spec;

try {
spec = JSON.parse(res.stdout);
spec = JSON.parse(fs.readFileSync(outputChainSpec).toString());
fs.unlinkSync(outputChainSpec);
} catch (e) {
return fatal('build spec failed', e);
}
Expand Down

0 comments on commit 45693e2

Please sign in to comment.