git.delta.rocks / unique-network / refs/commits / be0c28ab6ce3

difftreelog

source

node/src/command.rs4.0 KiBsourcehistory
1// This file is part of Substrate.23// Copyright (C) 2017-2020 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		"Substrate 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::BuildSpec(cmd)) => {70			let runner = cli.create_runner(cmd)?;71			runner.sync_run(|config| cmd.run(config.chain_spec, config.network))72		},73		Some(Subcommand::CheckBlock(cmd)) => {74			let runner = cli.create_runner(cmd)?;75			runner.async_run(|config| {76				let PartialComponents { client, task_manager, import_queue, ..}77					= service::new_partial(&config)?;78				Ok((cmd.run(client, import_queue), task_manager))79			})80		},81		Some(Subcommand::ExportBlocks(cmd)) => {82			let runner = cli.create_runner(cmd)?;83			runner.async_run(|config| {84				let PartialComponents { client, task_manager, ..}85					= service::new_partial(&config)?;86				Ok((cmd.run(client, config.database), task_manager))87			})88		},89		Some(Subcommand::ExportState(cmd)) => {90			let runner = cli.create_runner(cmd)?;91			runner.async_run(|config| {92				let PartialComponents { client, task_manager, ..}93					= service::new_partial(&config)?;94				Ok((cmd.run(client, config.chain_spec), task_manager))95			})96		},97		Some(Subcommand::ImportBlocks(cmd)) => {98			let runner = cli.create_runner(cmd)?;99			runner.async_run(|config| {100				let PartialComponents { client, task_manager, import_queue, ..}101					= service::new_partial(&config)?;102				Ok((cmd.run(client, import_queue), task_manager))103			})104		},105		Some(Subcommand::PurgeChain(cmd)) => {106			let runner = cli.create_runner(cmd)?;107			runner.sync_run(|config| cmd.run(config.database))108		},109		Some(Subcommand::Revert(cmd)) => {110			let runner = cli.create_runner(cmd)?;111			runner.async_run(|config| {112				let PartialComponents { client, task_manager, backend, ..}113					= service::new_partial(&config)?;114				Ok((cmd.run(client, backend), task_manager))115			})116		},117		Some(Subcommand::Benchmark(cmd)) => {118			if cfg!(feature = "runtime-benchmarks") {119				let runner = cli.create_runner(cmd)?;120121				runner.sync_run(|config| cmd.run::<Block, service::Executor>(config))122			} else {123				Err("Benchmarking wasn't enabled when building the node. \124				You can enable it with `--features runtime-benchmarks`.".into())125			}126		},127		None => {128			let runner = cli.create_runner(&cli.run)?;129			runner.run_node_until_exit(|config| match config.role {130				Role::Light => service::new_light(config),131				_ => service::new_full(config),132			})133		}134	}135}