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 121 122 123 124 125 126 #[clap(long)]127 pub no_hardware_benchmarks: bool,128129 130 #[structopt(raw = true)]131 pub relaychain_args: Vec<String>,132}133134impl Cli {135 pub fn node_name() -> String {136 match env::var(NODE_NAME_ENV).ok() {137 Some(name) => name,138 None => {139 if cfg!(feature = "unique-runtime") {140 "Unique"141 } else if cfg!(feature = "quartz-runtime") {142 "Quartz"143 } else {144 "Opal"145 }146 }147 .into(),148 }149 }150}151152#[derive(Debug)]153pub struct RelayChainCli {154 155 pub base: polkadot_cli::RunCmd,156157 158 pub chain_id: Option<String>,159160 161 pub base_path: Option<PathBuf>,162}163164impl RelayChainCli {165 166 pub fn new<'a>(167 para_config: &sc_service::Configuration,168 relay_chain_args: impl Iterator<Item = &'a String>,169 ) -> Self {170 let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);171 let chain_id = extension.map(|e| e.relay_chain.clone());172 let base_path = para_config173 .base_path174 .as_ref()175 .map(|x| x.path().join("polkadot"));176 Self {177 base_path,178 chain_id,179 base: polkadot_cli::RunCmd::parse_from(relay_chain_args),180 }181 }182}