Skip to content

Commit

Permalink
Add output positional arg to undying-collator cli (#2375)
Browse files Browse the repository at this point in the history
Follow up from #2370 to
add `output` positional argument to undying-collator.

cc @JoshOrndorff

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
  • Loading branch information
pepoviola and bkchr authored Nov 21, 2023
1 parent 0619049 commit 40afc77
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
11 changes: 10 additions & 1 deletion polkadot/parachain/test-parachains/undying/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 @@ -34,6 +35,10 @@ pub enum Subcommand {
/// Command for exporting the genesis state of the parachain
#[derive(Debug, Parser)]
pub struct ExportGenesisStateCommand {
/// Output file name or stdout if unspecified.
#[arg()]
pub output: Option<PathBuf>,

/// Id of the parachain this collator collates for.
#[arg(long, default_value_t = 100)]
pub parachain_id: u32,
Expand All @@ -50,7 +55,11 @@ pub struct ExportGenesisStateCommand {

/// 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: 23 additions & 3 deletions polkadot/parachain/test-parachains/undying/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_undying_collator::Collator;

mod cli;
Expand All @@ -35,14 +39,30 @@ fn main() -> Result<()> {
// `pov_size` and `pvf_complexity` need to match the ones that we start the collator
// with.
let collator = Collator::new(params.pov_size, params.pvf_complexity);
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)) => {
// We pass some dummy values for `pov_size` and `pvf_complexity` as these don't
// matter for `wasm` export.
println!("0x{:?}", HexDisplay::from(&Collator::default().validation_code()));
let output_buf =
format!("0x{:?}", HexDisplay::from(&Collator::default().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

0 comments on commit 40afc77

Please sign in to comment.