/home/runner/work/creditcoin/creditcoin/node/src/command.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use crate::{ |
2 | | chain_spec, |
3 | | cli::{Cli, Subcommand}, |
4 | | service, |
5 | | }; |
6 | | use creditcoin_node_runtime::Block; |
7 | | use sc_cli::{ChainSpec, Role, RuntimeVersion, SubstrateCli}; |
8 | | use sc_service::PartialComponents; |
9 | | |
10 | | impl SubstrateCli for Cli { |
11 | 0 | fn impl_name() -> String { |
12 | 0 | "Creditcoin Node".into() |
13 | 0 | } |
14 | | |
15 | 0 | fn impl_version() -> String { |
16 | 0 | env!("SUBSTRATE_CLI_IMPL_VERSION").into() |
17 | 0 | } |
18 | | |
19 | 0 | fn description() -> String { |
20 | 0 | env!("CARGO_PKG_DESCRIPTION").into() |
21 | 0 | } |
22 | | |
23 | 0 | fn author() -> String { |
24 | 0 | env!("CARGO_PKG_AUTHORS").into() |
25 | 0 | } |
26 | | |
27 | 0 | fn support_url() -> String { |
28 | 0 | "support.anonymous.an".into() |
29 | 0 | } |
30 | | |
31 | 0 | fn copyright_start_year() -> i32 { |
32 | 0 | 2017 |
33 | 0 | } |
34 | | |
35 | 0 | fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> { |
36 | 0 | Ok(match id { |
37 | 0 | "" => { |
38 | 0 | let msg = |
39 | 0 | "Please specify the chain with '--chain main' or '--chain test'".to_owned(); |
40 | 0 | log::error!("{}", msg); |
41 | 0 | return Err(msg); |
42 | | }, |
43 | 0 | "dev" => Box::new(chain_spec::development_config()?), |
44 | 0 | "local" => Box::new(chain_spec::local_testnet_config()?), |
45 | 0 | "test" | "testnet" => Box::new(chain_spec::testnet_config()?), |
46 | 0 | "main" | "mainnet" => Box::new(chain_spec::mainnet_config()?), |
47 | 0 | path => { |
48 | 0 | Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?) |
49 | | }, |
50 | | }) |
51 | 0 | } |
52 | | |
53 | 0 | fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion { |
54 | 0 | &creditcoin_node_runtime::VERSION |
55 | 0 | } |
56 | | } |
57 | | |
58 | | /// Parse and run command line arguments |
59 | 0 | pub fn run() -> sc_cli::Result<()> { |
60 | 0 | let cli = Cli::from_args(); |
61 | | |
62 | 0 | match &cli.subcommand { |
63 | 0 | Some(Subcommand::Key(cmd)) => cmd.run(&cli), |
64 | 0 | Some(Subcommand::BuildSpec(cmd)) => { |
65 | 0 | let runner = cli.create_runner(cmd)?; |
66 | 0 | runner.sync_run(|config| cmd.run(config.chain_spec, config.network)) |
67 | | }, |
68 | 0 | Some(Subcommand::CheckBlock(cmd)) => { |
69 | 0 | let runner = cli.create_runner(cmd)?; |
70 | 0 | runner.async_run(|config| { |
71 | 0 | let PartialComponents { client, task_manager, import_queue, .. } = |
72 | 0 | service::new_partial(&config)?; |
73 | 0 | Ok((cmd.run(client, import_queue), task_manager)) |
74 | 0 | }) |
75 | | }, |
76 | 0 | Some(Subcommand::ExportBlocks(cmd)) => { |
77 | 0 | let runner = cli.create_runner(cmd)?; |
78 | 0 | runner.async_run(|config| { |
79 | 0 | let PartialComponents { client, task_manager, .. } = service::new_partial(&config)?; |
80 | 0 | Ok((cmd.run(client, config.database), task_manager)) |
81 | 0 | }) |
82 | | }, |
83 | 0 | Some(Subcommand::ExportState(cmd)) => { |
84 | 0 | let runner = cli.create_runner(cmd)?; |
85 | 0 | runner.async_run(|config| { |
86 | 0 | let PartialComponents { client, task_manager, .. } = service::new_partial(&config)?; |
87 | 0 | Ok((cmd.run(client, config.chain_spec), task_manager)) |
88 | 0 | }) |
89 | | }, |
90 | 0 | Some(Subcommand::ImportBlocks(cmd)) => { |
91 | 0 | let runner = cli.create_runner(cmd)?; |
92 | 0 | runner.async_run(|config| { |
93 | 0 | let PartialComponents { client, task_manager, import_queue, .. } = |
94 | 0 | service::new_partial(&config)?; |
95 | 0 | Ok((cmd.run(client, import_queue), task_manager)) |
96 | 0 | }) |
97 | | }, |
98 | 0 | Some(Subcommand::PurgeChain(cmd)) => { |
99 | 0 | let runner = cli.create_runner(cmd)?; |
100 | 0 | runner.sync_run(|config| cmd.run(config.database)) |
101 | | }, |
102 | 0 | Some(Subcommand::Revert(cmd)) => { |
103 | 0 | let runner = cli.create_runner(cmd)?; |
104 | 0 | runner.async_run(|config| { |
105 | 0 | let PartialComponents { client, task_manager, backend, .. } = |
106 | 0 | service::new_partial(&config)?; |
107 | 0 | Ok((cmd.run(client, backend), task_manager)) |
108 | 0 | }) |
109 | | }, |
110 | 0 | Some(Subcommand::Benchmark(cmd)) => { |
111 | 0 | if cfg!(feature = "runtime-benchmarks") { |
112 | 0 | let runner = cli.create_runner(cmd)?; |
113 | | |
114 | 0 | runner.sync_run(|config| cmd.run::<Block, service::ExecutorDispatch>(config)) |
115 | | } else { |
116 | 0 | Err("Benchmarking wasn't enabled when building the node. You can enable it with \ |
117 | 0 | `--features runtime-benchmarks`." |
118 | 0 | .into()) |
119 | | } |
120 | | }, |
121 | | None => { |
122 | 0 | let runner = cli.create_runner(&cli.run)?; |
123 | 0 | runner.run_node_until_exit(|config| async move { |
124 | 0 | match config.role { |
125 | 0 | Role::Light => Err("Light clients are not supported at this time".into()), |
126 | 0 | _ => service::new_full(config, cli), |
127 | | } |
128 | 0 | .map_err(sc_cli::Error::Service) |
129 | 0 | }) |
130 | | }, |
131 | | } |
132 | 0 | } |