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

Add output positional arg to undying-collator cli #2375

Merged
merged 3 commits into from
Nov 21, 2023
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
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