Make export-genesis-wasm output hex (#236)

* Add --raw flag to export-genesis-state

* Switch export-genesis-wasm to hex by default

Also add --raw flag. This makes it similar to `export-genesis-state`.
This commit is contained in:
Sergei Shulepov
2020-11-11 20:27:35 +01:00
committed by GitHub
parent 572b4710d6
commit 2662bcd3dd
2 changed files with 24 additions and 6 deletions
+8
View File
@@ -63,6 +63,10 @@ pub struct ExportGenesisStateCommand {
#[structopt(long, default_value = "100")]
pub parachain_id: u32,
/// Write output in binary. Default is to write in hex.
#[structopt(short, long)]
pub raw: bool,
/// The name of the chain for that the genesis state should be exported.
#[structopt(long)]
pub chain: Option<String>,
@@ -75,6 +79,10 @@ pub struct ExportGenesisWasmCommand {
#[structopt(parse(from_os_str))]
pub output: Option<PathBuf>,
/// Write output in binary. Default is to write in hex.
#[structopt(short, long)]
pub raw: bool,
/// The name of the chain for that the genesis wasm file should be exported.
#[structopt(long)]
pub chain: Option<String>,
+16 -6
View File
@@ -223,12 +223,17 @@ pub fn run() -> Result<()> {
&params.chain.clone().unwrap_or_default(),
params.parachain_id.into(),
)?)?;
let header_hex = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
let raw_header = block.header().encode();
let output_buf = if params.raw {
raw_header
} else {
format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes()
};
if let Some(output) = &params.output {
std::fs::write(output, header_hex)?;
std::fs::write(output, output_buf)?;
} else {
print!("{}", header_hex);
std::io::stdout().write_all(&output_buf)?;
}
Ok(())
@@ -236,13 +241,18 @@ pub fn run() -> Result<()> {
Some(Subcommand::ExportGenesisWasm(params)) => {
sc_cli::init_logger("", sc_tracing::TracingReceiver::Log, None)?;
let wasm_file =
let raw_wasm_blob =
extract_genesis_wasm(&cli.load_spec(&params.chain.clone().unwrap_or_default())?)?;
let output_buf = if params.raw {
raw_wasm_blob
} else {
format!("0x{:?}", HexDisplay::from(&raw_wasm_blob)).into_bytes()
};
if let Some(output) = &params.output {
std::fs::write(output, wasm_file)?;
std::fs::write(output, output_buf)?;
} else {
std::io::stdout().write_all(&wasm_file)?;
std::io::stdout().write_all(&output_buf)?;
}
Ok(())