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 #[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]57 Benchmark(frame_benchmarking_cli::BenchmarkCmd),58}596061#[derive(Debug, Parser)]62pub struct ExportGenesisStateCommand {63 64 #[clap(parse(from_os_str))]65 pub output: Option<PathBuf>,6667 68 69 70 #[clap(long, conflicts_with = "chain")]71 pub parachain_id: Option<u32>,7273 74 #[clap(short, long)]75 pub raw: bool,7677 78 #[clap(long, conflicts_with = "parachain-id")]79 pub chain: Option<String>,80}818283#[derive(Debug, Parser)]84pub struct ExportGenesisWasmCommand {85 86 #[clap(parse(from_os_str))]87 pub output: Option<PathBuf>,8889 90 #[clap(short, long)]91 pub raw: bool,9293 94 #[clap(long)]95 pub chain: Option<String>,96}9798#[derive(Debug, Parser)]99#[clap(args_conflicts_with_subcommands = true, subcommand_negates_reqs = true)]100pub struct Cli {101 #[structopt(subcommand)]102 pub subcommand: Option<Subcommand>,103104 #[structopt(flatten)]105 pub run: cumulus_client_cli::RunCmd,106107 108 109 110 111 112 113 #[structopt(default_value = "500", long)]114 pub idle_autoseal_interval: u64,115116 117 #[structopt(raw = true)]118 pub relaychain_args: Vec<String>,119}120121impl Cli {122 pub fn node_name() -> String {123 match env::var(NODE_NAME_ENV).ok() {124 Some(name) => name,125 None => {126 if cfg!(feature = "unique-runtime") {127 "Unique"128 } else if cfg!(feature = "quartz-runtime") {129 "Quartz"130 } else {131 "Opal"132 }133 }134 .into(),135 }136 }137}138139#[derive(Debug)]140pub struct RelayChainCli {141 142 pub base: polkadot_cli::RunCmd,143144 145 pub chain_id: Option<String>,146147 148 pub base_path: Option<PathBuf>,149}150151impl RelayChainCli {152 153 pub fn new<'a>(154 para_config: &sc_service::Configuration,155 relay_chain_args: impl Iterator<Item = &'a String>,156 ) -> Self {157 let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);158 let chain_id = extension.map(|e| e.relay_chain.clone());159 let base_path = para_config160 .base_path161 .as_ref()162 .map(|x| x.path().join("polkadot"));163 Self {164 base_path,165 chain_id,166 base: polkadot_cli::RunCmd::parse_from(relay_chain_args),167 }168 }169}