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 ExportGenesisState(cumulus_client_cli::ExportGenesisStateCommand),2829 30 ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand),3132 33 BuildSpec(sc_cli::BuildSpecCmd),3435 36 CheckBlock(sc_cli::CheckBlockCmd),3738 39 ExportBlocks(sc_cli::ExportBlocksCmd),4041 42 ExportState(sc_cli::ExportStateCmd),4344 45 ImportBlocks(sc_cli::ImportBlocksCmd),4647 48 PurgeChain(cumulus_client_cli::PurgeChainCmd),4950 51 Revert(sc_cli::RevertCmd),5253 54 #[clap(subcommand)]55 #[cfg(feature = "runtime-benchmarks")]56 Benchmark(frame_benchmarking_cli::BenchmarkCmd),5758 59 TryRuntime(try_runtime_cli::TryRuntimeCmd),60}6162#[derive(Debug, Parser)]63#[clap(args_conflicts_with_subcommands = true, subcommand_negates_reqs = true)]64pub struct Cli {65 #[structopt(subcommand)]66 pub subcommand: Option<Subcommand>,6768 #[structopt(flatten)]69 pub run: cumulus_client_cli::RunCmd,7071 72 73 74 75 76 77 #[structopt(default_value = "500", long)]78 pub idle_autoseal_interval: u64,7980 81 82 83 84 85 86 87 #[clap(long)]88 pub no_hardware_benchmarks: bool,8990 91 #[structopt(raw = true)]92 pub relaychain_args: Vec<String>,93}9495impl Cli {96 pub fn node_name() -> String {97 match env::var(NODE_NAME_ENV).ok() {98 Some(name) => name,99 None => {100 if cfg!(feature = "unique-runtime") {101 "Unique"102 } else if cfg!(feature = "quartz-runtime") {103 "Quartz"104 } else if cfg!(feature = "sapphire-runtime") {105 "Sapphire"106 } else {107 "Opal"108 }109 }110 .into(),111 }112 }113}114115#[derive(Debug)]116pub struct RelayChainCli {117 118 pub base: polkadot_cli::RunCmd,119120 121 pub chain_id: Option<String>,122123 124 pub base_path: Option<PathBuf>,125}126127impl RelayChainCli {128 129 pub fn new<'a>(130 para_config: &sc_service::Configuration,131 relay_chain_args: impl Iterator<Item = &'a String>,132 ) -> Self {133 let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);134 let chain_id = extension.map(|e| e.relay_chain.clone());135 let base_path = para_config136 .base_path137 .as_ref()138 .map(|x| x.path().join("polkadot"));139 Self {140 base_path,141 chain_id,142 base: polkadot_cli::RunCmd::parse_from(relay_chain_args),143 }144 }145}