@@ -78,20 +78,20 @@ const stripChainspecJsonName = (chain: string) => {
7878 * @param chain
7979 */
8080const getChainspec = ( image : string , chain : string ) => {
81- const outputChainSpec = `${ shell . tempdir ( ) } /${ chain } -${ new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) } .json` ;
81+ const tmpChainSpec = `${ shell . tempdir ( ) } /${ chain } -${ new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) } .json` ;
8282 if ( chain . endsWith ( '.json' ) ) {
8383 exec (
84- `docker run -v $(pwd)/${ chain } :/${ chain } --rm ${ image } build-spec --chain=/${ chain } --disable-default-bootnode > ${ outputChainSpec } ` ,
84+ `docker run -v $(pwd)/${ chain } :/${ chain } --rm ${ image } build-spec --chain=/${ chain } --disable-default-bootnode > ${ tmpChainSpec } ` ,
8585 ) ;
8686 } else {
87- exec ( `docker run --rm ${ image } build-spec --chain=${ chain } --disable-default-bootnode > ${ outputChainSpec } ` ) ;
87+ exec ( `docker run --rm ${ image } build-spec --chain=${ chain } --disable-default-bootnode > ${ tmpChainSpec } ` ) ;
8888 }
8989
9090 let spec ;
9191
9292 try {
93- spec = JSON . parse ( fs . readFileSync ( outputChainSpec ) . toString ( ) ) ;
94- fs . unlinkSync ( outputChainSpec ) ;
93+ spec = JSON . parse ( fs . readFileSync ( tmpChainSpec ) . toString ( ) ) ;
94+ shell . rm ( tmpChainSpec ) ;
9595 } catch ( e ) {
9696 return fatal ( 'build spec failed' , e ) ;
9797 }
@@ -117,11 +117,24 @@ const exportParachainGenesis = (parachain: Parachain, output: string) => {
117117 }
118118
119119 const absOutput = output . startsWith ( '/' ) ? output : `$(pwd)/"${ output } "` ;
120- const res2 = exec ( `docker run -v "${ absOutput } ":/app --rm ${ parachain . image } export-genesis-wasm ${ args . join ( ' ' ) } ` ) ;
121- const wasm = res2 . stdout . trim ( ) ;
122120
123- const res = exec ( `docker run -v "${ absOutput } ":/app --rm ${ parachain . image } export-genesis-state ${ args . join ( ' ' ) } ` ) ;
124- const state = res . stdout . trim ( ) ;
121+ const tmpGenesisWasm = `${ shell . tempdir ( ) } /genesis-wasm-${ new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) } ` ;
122+ exec (
123+ `docker run -v "${ absOutput } ":/app --rm ${ parachain . image } export-genesis-wasm ${ args . join (
124+ ' ' ,
125+ ) } > ${ tmpGenesisWasm } `,
126+ ) ;
127+ const wasm = fs . readFileSync ( tmpGenesisWasm ) . toString ( ) . trim ( ) ;
128+ shell . rm ( tmpGenesisWasm ) ;
129+
130+ const tmpGenesisState = `${ shell . tempdir ( ) } /genesis-state-${ new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) } ` ;
131+ exec (
132+ `docker run -v "${ absOutput } ":/app --rm ${ parachain . image } export-genesis-state ${ args . join (
133+ ' ' ,
134+ ) } > ${ tmpGenesisState } `,
135+ ) ;
136+ const state = fs . readFileSync ( tmpGenesisState ) . toString ( ) . trim ( ) ;
137+ shell . rm ( tmpGenesisState ) ;
125138
126139 return { state, wasm } ;
127140} ;
0 commit comments