git.delta.rocks / unique-network / refs/commits / 20ec6e66cd9b

difftreelog

source

node/cli/src/cli.rs4.3 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use crate::chain_spec;18use std::{path::PathBuf, env};19use clap::Parser;2021const NODE_NAME_ENV: &str = "UNIQUE_NODE_NAME";2223/// Sub-commands supported by the collator.24#[derive(Debug, Parser)]25pub enum Subcommand {26	/// Export the genesis state of the parachain.27	ExportGenesisState(cumulus_client_cli::ExportGenesisStateCommand),2829	/// Export the genesis wasm of the parachain.30	ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand),3132	/// Build a chain specification.33	BuildSpec(sc_cli::BuildSpecCmd),3435	/// Validate blocks.36	CheckBlock(sc_cli::CheckBlockCmd),3738	/// Export blocks.39	ExportBlocks(sc_cli::ExportBlocksCmd),4041	/// Export the state of a given block into a chain spec.42	ExportState(sc_cli::ExportStateCmd),4344	/// Import blocks.45	ImportBlocks(sc_cli::ImportBlocksCmd),4647	/// Remove the whole chain.48	PurgeChain(cumulus_client_cli::PurgeChainCmd),4950	/// Revert the chain to a previous state.51	Revert(sc_cli::RevertCmd),5253	/// The custom benchmark subcommmand benchmarking runtime pallets.54	#[clap(subcommand)]55	#[cfg(feature = "runtime-benchmarks")]56	Benchmark(frame_benchmarking_cli::BenchmarkCmd),5758	/// Try runtime59	#[cfg(feature = "try-runtime")]60	TryRuntime(try_runtime_cli::TryRuntimeCmd),6162	/// Try runtime. Note: `try-runtime` feature must be enabled.63	#[cfg(not(feature = "try-runtime"))]64	TryRuntime,65}6667#[derive(Debug, Parser)]68#[clap(args_conflicts_with_subcommands = true, subcommand_negates_reqs = true)]69pub struct Cli {70	#[structopt(subcommand)]71	pub subcommand: Option<Subcommand>,7273	#[structopt(flatten)]74	pub run: cumulus_client_cli::RunCmd,7576	/// When running the node in the `--dev` mode and77	/// there is no transaction in the transaction pool,78	/// an empty block will be sealed automatically79	/// after the `--idle-autoseal-interval` milliseconds.80	///81	/// The default interval is 500 milliseconds82	#[structopt(default_value = "500", long)]83	pub idle_autoseal_interval: u64,8485	/// Disable automatic hardware benchmarks.86	///87	/// By default these benchmarks are automatically ran at startup and measure88	/// the CPU speed, the memory bandwidth and the disk speed.89	///90	/// The results are then printed out in the logs, and also sent as part of91	/// telemetry, if telemetry is enabled.92	#[clap(long)]93	pub no_hardware_benchmarks: bool,9495	/// Relaychain arguments96	#[structopt(raw = true)]97	pub relaychain_args: Vec<String>,98}99100impl Cli {101	pub fn node_name() -> String {102		match env::var(NODE_NAME_ENV).ok() {103			Some(name) => name,104			None => {105				if cfg!(feature = "unique-runtime") {106					"Unique"107				} else if cfg!(feature = "quartz-runtime") {108					"Quartz"109				} else if cfg!(feature = "sapphire-runtime") {110					"Sapphire"111				} else {112					"Opal"113				}114			}115			.into(),116		}117	}118}119120#[derive(Debug)]121pub struct RelayChainCli {122	/// The actual relay chain cli object.123	pub base: polkadot_cli::RunCmd,124125	/// Optional chain id that should be passed to the relay chain.126	pub chain_id: Option<String>,127128	/// The base path that should be used by the relay chain.129	pub base_path: Option<PathBuf>,130}131132impl RelayChainCli {133	/// Parse the relay chain CLI parameters using the para chain `Configuration`.134	pub fn new<'a>(135		para_config: &sc_service::Configuration,136		relay_chain_args: impl Iterator<Item = &'a String>,137	) -> Self {138		let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);139		let chain_id = extension.map(|e| e.relay_chain.clone());140		let base_path = para_config141			.base_path142			.as_ref()143			.map(|x| x.path().join("polkadot"));144		Self {145			base_path,146			chain_id,147			base: polkadot_cli::RunCmd::parse_from(relay_chain_args),148		}149	}150}