Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adder Parachain: Accept output file argument to export-genesis-* subcommands #2370

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions polkadot/parachain/test-parachains/adder/collator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use clap::Parser;
use sc_cli::SubstrateCli;
use std::path::PathBuf;

/// Sub-commands supported by the collator.
#[derive(Debug, Parser)]
Expand All @@ -33,11 +34,19 @@ pub enum Subcommand {

/// Command for exporting the genesis head data of the parachain
#[derive(Debug, Parser)]
pub struct ExportGenesisHeadCommand {}
pub struct ExportGenesisHeadCommand {
/// Output file name or stdout if unspecified.
#[arg()]
pub output: Option<PathBuf>,
}

/// Command for exporting the genesis wasm file.
#[derive(Debug, Parser)]
pub struct ExportGenesisWasmCommand {}
pub struct ExportGenesisWasmCommand {
/// Output file name or stdout if unspecified.
#[arg()]
pub output: Option<PathBuf>,
}

#[allow(missing_docs)]
#[derive(Debug, Parser)]
Expand Down
26 changes: 22 additions & 4 deletions polkadot/parachain/test-parachains/adder/collator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ use polkadot_node_subsystem::messages::{CollationGenerationMessage, CollatorProt
use polkadot_primitives::Id as ParaId;
use sc_cli::{Error as SubstrateCliError, SubstrateCli};
use sp_core::hexdisplay::HexDisplay;
use std::{
fs,
io::{self, Write},
};
use test_parachain_adder_collator::Collator;

/// The parachain ID to collate for in case it wasn't set explicitly through CLI.
Expand All @@ -34,15 +38,29 @@ fn main() -> Result<()> {
let cli = Cli::from_args();

match cli.subcommand {
Some(cli::Subcommand::ExportGenesisState(_params)) => {
Some(cli::Subcommand::ExportGenesisState(params)) => {
let collator = Collator::new();
println!("0x{:?}", HexDisplay::from(&collator.genesis_head()));
let output_buf =
format!("0x{:?}", HexDisplay::from(&collator.genesis_head())).into_bytes();

if let Some(output) = params.output {
std::fs::write(output, output_buf)?;
} else {
std::io::stdout().write_all(&output_buf)?;
}

Ok::<_, Error>(())
},
Some(cli::Subcommand::ExportGenesisWasm(_params)) => {
Some(cli::Subcommand::ExportGenesisWasm(params)) => {
let collator = Collator::new();
println!("0x{:?}", HexDisplay::from(&collator.validation_code()));
let output_buf =
format!("0x{:?}", HexDisplay::from(&collator.validation_code())).into_bytes();

if let Some(output) = params.output {
fs::write(output, output_buf)?;
} else {
io::stdout().write_all(&output_buf)?;
}

Ok(())
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ fn main() -> Result<()> {
Some(cli::Subcommand::ExportGenesisWasm(params)) => {
// We pass some dummy values for `pov_size` and `pvf_complexity` as these don't
// matter for `wasm` export.
let collator = Collator::default();
let output_buf =
format!("0x{:?}", HexDisplay::from(&Collator::default().validation_code()))
.into_bytes();
format!("0x{:?}", HexDisplay::from(&collator.validation_code())).into_bytes();

if let Some(output) = params.output {
fs::write(output, output_buf)?;
Expand Down