Skip to content

Commit

Permalink
fix export genesis state (#1233)
Browse files Browse the repository at this point in the history
* fix export genesis state

Signed-off-by: Ermal Kaleci <[email protected]>
  • Loading branch information
ermalkaleci authored May 6, 2024
1 parent 1722e4c commit e2d0097
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions bin/collator/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use sc_service::{
use sp_core::hexdisplay::HexDisplay;
use sp_runtime::traits::AccountIdConversion;
use sp_runtime::traits::Block as BlockT;
use std::{io::Write, net::SocketAddr};
use std::net::SocketAddr;

#[cfg(feature = "runtime-benchmarks")]
use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE};
Expand Down Expand Up @@ -456,22 +456,35 @@ pub fn run() -> Result<()> {
}
}
Some(Subcommand::ExportGenesisState(cmd)) => {
let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
let state_version = Cli::runtime_version(&spec).state_version();

let block: Block = generate_genesis_block(&*spec, state_version)?;
let raw_header = block.header().encode();
let output_buf = if cmd.raw {
raw_header
} else {
format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes()
};
if let Some(output) = &cmd.output {
std::fs::write(output, output_buf)?;
let runner = cli.create_runner(cmd)?;
if runner.config().chain_spec.is_astar() {
runner.sync_run(|config| {
let PartialComponents { client, .. } =
parachain::new_partial::<astar::RuntimeApi, astar::Executor, _>(
&config,
parachain::build_import_queue,
)?;
cmd.run(config.chain_spec.as_ref(), client.as_ref())
})
} else if runner.config().chain_spec.is_shiden() {
runner.sync_run(|config| {
let PartialComponents { client, .. } =
parachain::new_partial::<shiden::RuntimeApi, shiden::Executor, _>(
&config,
parachain::build_import_queue,
)?;
cmd.run(config.chain_spec.as_ref(), client.as_ref())
})
} else {
std::io::stdout().write_all(&output_buf)?;
runner.sync_run(|config| {
let PartialComponents { client, .. } =
parachain::new_partial::<shibuya::RuntimeApi, shibuya::Executor, _>(
&config,
parachain::build_import_queue,
)?;
cmd.run(config.chain_spec.as_ref(), client.as_ref())
})
}
Ok(())
}
Some(Subcommand::ExportGenesisWasm(cmd)) => {
let runner = cli.create_runner(cmd)?;
Expand Down

0 comments on commit e2d0097

Please sign in to comment.