git.delta.rocks / unique-network / refs/commits / 78924d5e6628

difftreelog

source

node/src/cli.rs3.8 KiBsourcehistory
1use crate::chain_spec;2use sc_cli;3use std::path::PathBuf;4use structopt::StructOpt;56/// Sub-commands supported by the collator.7#[derive(Debug, StructOpt)]8pub enum Subcommand {9	/// Export the genesis state of the parachain.10	#[structopt(name = "export-genesis-state")]11	ExportGenesisState(ExportGenesisStateCommand),1213	/// Export the genesis wasm of the parachain.14	#[structopt(name = "export-genesis-wasm")]15	ExportGenesisWasm(ExportGenesisWasmCommand),1617	/// Build a chain specification.18	BuildSpec(sc_cli::BuildSpecCmd),1920	/// Validate blocks.21	CheckBlock(sc_cli::CheckBlockCmd),2223	/// Export blocks.24	ExportBlocks(sc_cli::ExportBlocksCmd),2526	/// Export the state of a given block into a chain spec.27	ExportState(sc_cli::ExportStateCmd),2829	/// Import blocks.30	ImportBlocks(sc_cli::ImportBlocksCmd),3132	/// Remove the whole chain.33	PurgeChain(cumulus_client_cli::PurgeChainCmd),3435	/// Revert the chain to a previous state.36	Revert(sc_cli::RevertCmd),37}3839/// Command for exporting the genesis state of the parachain40#[derive(Debug, StructOpt)]41pub struct ExportGenesisStateCommand {42	/// Output file name or stdout if unspecified.43	#[structopt(parse(from_os_str))]44	pub output: Option<PathBuf>,4546	/// Id of the parachain this state is for.47	///48	/// Default: 10049	#[structopt(long, conflicts_with = "chain")]50	pub parachain_id: Option<u32>,5152	/// Write output in binary. Default is to write in hex.53	#[structopt(short, long)]54	pub raw: bool,5556	/// The name of the chain for that the genesis state should be exported.57	#[structopt(long, conflicts_with = "parachain-id")]58	pub chain: Option<String>,59}6061/// Command for exporting the genesis wasm file.62#[derive(Debug, StructOpt)]63pub struct ExportGenesisWasmCommand {64	/// Output file name or stdout if unspecified.65	#[structopt(parse(from_os_str))]66	pub output: Option<PathBuf>,6768	/// Write output in binary. Default is to write in hex.69	#[structopt(short, long)]70	pub raw: bool,7172	/// The name of the chain for that the genesis wasm file should be exported.73	#[structopt(long)]74	pub chain: Option<String>,75}7677#[derive(Debug, StructOpt)]78pub struct RunCmd {79	#[structopt(flatten)]80	pub base: sc_cli::RunCmd,8182	/// Id of the parachain this collator collates for.83	#[structopt(long)]84	pub parachain_id: Option<u32>,85}8687impl std::ops::Deref for RunCmd {88	type Target = sc_cli::RunCmd;8990	fn deref(&self) -> &Self::Target {91		&self.base92	}93}9495#[derive(Debug, StructOpt)]96#[structopt(settings = &[97	structopt::clap::AppSettings::GlobalVersion,98	structopt::clap::AppSettings::ArgsNegateSubcommands,99	structopt::clap::AppSettings::SubcommandsNegateReqs,100])]101pub struct Cli {102	#[structopt(subcommand)]103	pub subcommand: Option<Subcommand>,104105	#[structopt(flatten)]106	pub run: RunCmd,107108	/// Run node as collator.109	///110	/// Note that this is the same as running with `--validator`.111	#[structopt(long, conflicts_with = "validator")]112	pub collator: bool,113114	/// Relaychain arguments115	#[structopt(raw = true)]116	pub relaychain_args: Vec<String>,117}118119#[derive(Debug)]120pub struct RelayChainCli {121	/// The actual relay chain cli object.122	pub base: polkadot_cli::RunCmd,123124	/// Optional chain id that should be passed to the relay chain.125	pub chain_id: Option<String>,126127	/// The base path that should be used by the relay chain.128	pub base_path: Option<PathBuf>,129}130131impl RelayChainCli {132	/// Parse the relay chain CLI parameters using the para chain `Configuration`.133	pub fn new<'a>(134		para_config: &sc_service::Configuration,135		relay_chain_args: impl Iterator<Item = &'a String>,136	) -> Self {137		let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);138		let chain_id = extension.map(|e| e.relay_chain.clone());139		let base_path = para_config140			.base_path141			.as_ref()142			.map(|x| x.path().join("polkadot"));143		Self {144			base_path,145			chain_id,146			base: polkadot_cli::RunCmd::from_iter(relay_chain_args),147		}148	}149}