mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 16:57:58 +00:00
5f751e4472
* :) * Slight tidy * Remove ServiceBuilderCommand * Remove whitespace * Keep task manager alive for check_block/import_blocks * Pass task_manager to run_until_exit * Make task_manager in run_until_exit and make subcommands async * Change the async_run fn to return a future and task manager * async_run should take a result fn * Apply suggestions from code review Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Fix spaces in export_raw_state Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
107 lines
3.1 KiB
Rust
107 lines
3.1 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
use crate::{chain_spec, service, Cli, Subcommand};
|
|
use node_executor::Executor;
|
|
use node_runtime::{Block, RuntimeApi};
|
|
use sc_cli::{Result, SubstrateCli, RuntimeVersion, Role, ChainSpec};
|
|
|
|
impl SubstrateCli for Cli {
|
|
fn impl_name() -> &'static str {
|
|
"Substrate Node"
|
|
}
|
|
|
|
fn impl_version() -> &'static str {
|
|
env!("SUBSTRATE_CLI_IMPL_VERSION")
|
|
}
|
|
|
|
fn description() -> &'static str {
|
|
env!("CARGO_PKG_DESCRIPTION")
|
|
}
|
|
|
|
fn author() -> &'static str {
|
|
env!("CARGO_PKG_AUTHORS")
|
|
}
|
|
|
|
fn support_url() -> &'static str {
|
|
"https://github.com/paritytech/substrate/issues/new"
|
|
}
|
|
|
|
fn copyright_start_year() -> i32 {
|
|
2017
|
|
}
|
|
|
|
fn executable_name() -> &'static str {
|
|
"substrate"
|
|
}
|
|
|
|
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
|
|
Ok(match id {
|
|
"dev" => Box::new(chain_spec::development_config()),
|
|
"local" => Box::new(chain_spec::local_testnet_config()),
|
|
"" | "fir" | "flaming-fir" => Box::new(chain_spec::flaming_fir_config()?),
|
|
"staging" => Box::new(chain_spec::staging_testnet_config()),
|
|
path => Box::new(chain_spec::ChainSpec::from_json_file(
|
|
std::path::PathBuf::from(path),
|
|
)?),
|
|
})
|
|
}
|
|
|
|
fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
|
|
&node_runtime::VERSION
|
|
}
|
|
}
|
|
|
|
/// Parse command line arguments into service configuration.
|
|
pub fn run() -> Result<()> {
|
|
let cli = Cli::from_args();
|
|
|
|
match &cli.subcommand {
|
|
None => {
|
|
let runner = cli.create_runner(&cli.run)?;
|
|
runner.run_node_until_exit(|config| match config.role {
|
|
Role::Light => service::new_light(config),
|
|
_ => service::new_full(config),
|
|
})
|
|
}
|
|
Some(Subcommand::Inspect(cmd)) => {
|
|
let runner = cli.create_runner(cmd)?;
|
|
|
|
runner.sync_run(|config| cmd.run::<Block, RuntimeApi, Executor>(config))
|
|
}
|
|
Some(Subcommand::Benchmark(cmd)) => {
|
|
if cfg!(feature = "runtime-benchmarks") {
|
|
let runner = cli.create_runner(cmd)?;
|
|
|
|
runner.sync_run(|config| cmd.run::<Block, Executor>(config))
|
|
} else {
|
|
println!("Benchmarking wasn't enabled when building the node. \
|
|
You can enable it with `--features runtime-benchmarks`.");
|
|
Ok(())
|
|
}
|
|
}
|
|
Some(Subcommand::Base(subcommand)) => {
|
|
let runner = cli.create_runner(subcommand)?;
|
|
runner.run_subcommand(subcommand, |config| {
|
|
let (builder, _, _, _) = new_full_start!(config);
|
|
Ok(builder.to_chain_ops_parts())
|
|
})
|
|
}
|
|
}
|
|
}
|