1234567891011121314151617use crate::chain_spec;18use std::{path::PathBuf, env};19use clap::Parser;2021const NODE_NAME_ENV: &str = "UNIQUE_NODE_NAME";222324#[derive(Debug, Parser)]25pub enum Subcommand {26 27 #[clap(name = "export-genesis-state")]28 ExportGenesisState(ExportGenesisStateCommand),2930 31 #[clap(name = "export-genesis-wasm")]32 ExportGenesisWasm(ExportGenesisWasmCommand),3334 35 BuildSpec(sc_cli::BuildSpecCmd),3637 38 CheckBlock(sc_cli::CheckBlockCmd),3940 41 ExportBlocks(sc_cli::ExportBlocksCmd),4243 44 ExportState(sc_cli::ExportStateCmd),4546 47 ImportBlocks(sc_cli::ImportBlocksCmd),4849 50 PurgeChain(cumulus_client_cli::PurgeChainCmd),5152 53 Revert(sc_cli::RevertCmd),5455 56 #[clap(subcommand)]57 Benchmark(frame_benchmarking_cli::BenchmarkCmd),5859 60 TryRuntime(try_runtime_cli::TryRuntimeCmd),61}626364#[derive(Debug, Parser)]65pub struct ExportGenesisStateCommand {66 67 #[clap(parse(from_os_str))]68 pub output: Option<PathBuf>,6970 71 72 73 #[clap(long, conflicts_with = "chain")]74 pub parachain_id: Option<u32>,7576 77 #[clap(short, long)]78 pub raw: bool,7980 81 #[clap(long, conflicts_with = "parachain-id")]82 pub chain: Option<String>,83}848586#[derive(Debug, Parser)]87pub struct ExportGenesisWasmCommand {88 89 #[clap(parse(from_os_str))]90 pub output: Option<PathBuf>,9192 93 #[clap(short, long)]94 pub raw: bool,9596 97 #[clap(long)]98 pub chain: Option<String>,99}100101#[derive(Debug, Parser)]102#[clap(args_conflicts_with_subcommands = true, subcommand_negates_reqs = true)]103pub struct Cli {104 #[structopt(subcommand)]105 pub subcommand: Option<Subcommand>,106107 #[structopt(flatten)]108 pub run: cumulus_client_cli::RunCmd,109110 111 112 113 114 115 116 #[structopt(default_value = "500", long)]117 pub idle_autoseal_interval: u64,118119 120 #[structopt(raw = true)]121 pub relaychain_args: Vec<String>,122}123124impl Cli {125 pub fn node_name() -> String {126 match env::var(NODE_NAME_ENV).ok() {127 Some(name) => name,128 None => {129 if cfg!(feature = "unique-runtime") {130 "Unique"131 } else if cfg!(feature = "quartz-runtime") {132 "Quartz"133 } else {134 "Opal"135 }136 }137 .into(),138 }139 }140}141142#[derive(Debug)]143pub struct RelayChainCli {144 145 pub base: polkadot_cli::RunCmd,146147 148 pub chain_id: Option<String>,149150 151 pub base_path: Option<PathBuf>,152}153154impl RelayChainCli {155 156 pub fn new<'a>(157 para_config: &sc_service::Configuration,158 relay_chain_args: impl Iterator<Item = &'a String>,159 ) -> Self {160 let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);161 let chain_id = extension.map(|e| e.relay_chain.clone());162 let base_path = para_config163 .base_path164 .as_ref()165 .map(|x| x.path().join("polkadot"));166 Self {167 base_path,168 chain_id,169 base: polkadot_cli::RunCmd::parse_from(relay_chain_args),170 }171 }172}