git.delta.rocks / unique-network / refs/commits / 2eedf4593dca

difftreelog

source

node/src/command.rs4.1 KiBsourcehistory
1// This file is part of Substrate.23// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.4// SPDX-License-Identifier: Apache-2.056// Licensed under the Apache License, Version 2.0 (the "License");7// you may not use this file except in compliance with the License.8// You may obtain a copy of the License at9//10// 	http://www.apache.org/licenses/LICENSE-2.011//12// Unless required by applicable law or agreed to in writing, software13// distributed under the License is distributed on an "AS IS" BASIS,14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15// See the License for the specific language governing permissions and16// limitations under the License.1718use crate::{chain_spec, service};19use crate::cli::{Cli, Subcommand};20use sc_cli::{SubstrateCli, RuntimeVersion, Role, ChainSpec};21use sc_service::PartialComponents;22use nft_runtime::Block;2324impl SubstrateCli for Cli {25	fn impl_name() -> String {26		"Unique Node".into()27	}2829	fn impl_version() -> String {30		env!("SUBSTRATE_CLI_IMPL_VERSION").into()31	}3233	fn description() -> String {34		env!("CARGO_PKG_DESCRIPTION").into()35	}3637	fn author() -> String {38		env!("CARGO_PKG_AUTHORS").into()39	}4041	fn support_url() -> String {42		"support.anonymous.an".into()43	}4445	fn copyright_start_year() -> i32 {46		201747	}4849	fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {50		Ok(match id {51			"dev" => Box::new(chain_spec::development_config()?),52			"" | "local" => Box::new(chain_spec::local_testnet_config()?),53			path => Box::new(chain_spec::ChainSpec::from_json_file(54				std::path::PathBuf::from(path),55			)?),56		})57	}5859	fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {60		&nft_runtime::VERSION61	}62}6364/// Parse and run command line arguments65pub fn run() -> sc_cli::Result<()> {66	let cli = Cli::from_args();6768	match &cli.subcommand {69		Some(Subcommand::Key(cmd)) => cmd.run(&cli),70		Some(Subcommand::BuildSpec(cmd)) => {71			let runner = cli.create_runner(cmd)?;72			runner.sync_run(|config| cmd.run(config.chain_spec, config.network))73		},74		Some(Subcommand::CheckBlock(cmd)) => {75			let runner = cli.create_runner(cmd)?;76			runner.async_run(|config| {77				let PartialComponents { client, task_manager, import_queue, ..}78					= service::new_partial(&config)?;79				Ok((cmd.run(client, import_queue), task_manager))80			})81		},82		Some(Subcommand::ExportBlocks(cmd)) => {83			let runner = cli.create_runner(cmd)?;84			runner.async_run(|config| {85				let PartialComponents { client, task_manager, ..}86					= service::new_partial(&config)?;87				Ok((cmd.run(client, config.database), task_manager))88			})89		},90		Some(Subcommand::ExportState(cmd)) => {91			let runner = cli.create_runner(cmd)?;92			runner.async_run(|config| {93				let PartialComponents { client, task_manager, ..}94					= service::new_partial(&config)?;95				Ok((cmd.run(client, config.chain_spec), task_manager))96			})97		},98		Some(Subcommand::ImportBlocks(cmd)) => {99			let runner = cli.create_runner(cmd)?;100			runner.async_run(|config| {101				let PartialComponents { client, task_manager, import_queue, ..}102					= service::new_partial(&config)?;103				Ok((cmd.run(client, import_queue), task_manager))104			})105		},106		Some(Subcommand::PurgeChain(cmd)) => {107			let runner = cli.create_runner(cmd)?;108			runner.sync_run(|config| cmd.run(config.database))109		},110		Some(Subcommand::Revert(cmd)) => {111			let runner = cli.create_runner(cmd)?;112			runner.async_run(|config| {113				let PartialComponents { client, task_manager, backend, ..}114					= service::new_partial(&config)?;115				Ok((cmd.run(client, backend), task_manager))116			})117		},118		Some(Subcommand::Benchmark(cmd)) => {119			if cfg!(feature = "runtime-benchmarks") {120				let runner = cli.create_runner(cmd)?;121122				runner.sync_run(|config| cmd.run::<Block, service::Executor>(config))123			} else {124				Err("Benchmarking wasn't enabled when building the node. \125				You can enable it with `--features runtime-benchmarks`.".into())126			}127		},128		None => {129			let runner = cli.create_runner(&cli.run)?;130			runner.run_node_until_exit(|config| async move {131				match config.role {132					Role::Light => service::new_light(config),133					_ => service::new_full(config),134				}.map_err(sc_cli::Error::Service)135			})136		}137	}138}