Newer
Older
Cecile Tonglet
committed
// This file is part of Substrate.
// Copyright (C) 2018-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
Cecile Tonglet
committed
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
Cecile Tonglet
committed
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
Cecile Tonglet
committed
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Cecile Tonglet
committed
// 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/>.
Cecile Tonglet
committed
mod build_spec_cmd;
mod check_block_cmd;
Cecile Tonglet
committed
mod export_blocks_cmd;
Cecile Tonglet
committed
mod import_blocks_cmd;
Cecile Tonglet
committed
mod purge_chain_cmd;
mod sign;
mod verify;
mod vanity;
Cecile Tonglet
committed
mod revert_cmd;
mod generate_node_key;
mod generate;
mod insert;
mod inspect_node_key;
mod inspect;
mod key;
pub mod utils;
Cecile Tonglet
committed
use std::fmt::Debug;
use structopt::StructOpt;
Cecile Tonglet
committed
pub use self::{
build_spec_cmd::BuildSpecCmd,
check_block_cmd::CheckBlockCmd,
export_blocks_cmd::ExportBlocksCmd,
export_state_cmd::ExportStateCmd,
import_blocks_cmd::ImportBlocksCmd,
purge_chain_cmd::PurgeChainCmd,
sign::SignCmd,
generate::GenerateCmd,
insert::InsertCmd,
inspect::InspectCmd,
generate_node_key::GenerateNodeKeyCmd,
inspect_node_key::InspectNodeKeyCmd,
key::KeySubcommand,
vanity::VanityCmd,
verify::VerifyCmd,
revert_cmd::RevertCmd,
run_cmd::RunCmd,
};
Cecile Tonglet
committed
/// All core commands that are provided by default.
///
/// The core commands are split into multiple subcommands and `Run` is the default subcommand. From
/// the CLI user perspective, it is not visible that `Run` is a subcommand. So, all parameters of
/// `Run` are exported as main executable parameters.
Cecile Tonglet
committed
#[derive(Debug, StructOpt)]
Cecile Tonglet
committed
pub enum Subcommand {
/// Build a spec.json file, outputs to stdout.
Cecile Tonglet
committed
BuildSpec(BuildSpecCmd),
Cecile Tonglet
committed
/// Export blocks to a file.
Cecile Tonglet
committed
ExportBlocks(ExportBlocksCmd),
Cecile Tonglet
committed
/// Import blocks from file.
Cecile Tonglet
committed
ImportBlocks(ImportBlocksCmd),
Cecile Tonglet
committed
/// Validate a single block.
Cecile Tonglet
committed
CheckBlock(CheckBlockCmd),
Cecile Tonglet
committed
/// Export state as raw chain spec.
ExportState(ExportStateCmd),
Cecile Tonglet
committed
/// Revert chain to the previous state.
Cecile Tonglet
committed
Revert(RevertCmd),
Cecile Tonglet
committed
/// Remove the whole chain data.
Cecile Tonglet
committed
PurgeChain(PurgeChainCmd),
Cecile Tonglet
committed
}
Cecile Tonglet
committed
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/// Macro that helps implement CliConfiguration on an enum of subcommand automatically
///
/// # Example
///
/// ```
/// # #[macro_use] extern crate sc_cli;
///
/// # struct EmptyVariant {}
///
/// # impl sc_cli::CliConfiguration for EmptyVariant {
/// # fn shared_params(&self) -> &sc_cli::SharedParams { unimplemented!() }
/// # fn chain_id(&self, _: bool) -> sc_cli::Result<String> { Ok("test-chain-id".to_string()) }
/// # }
///
/// # fn main() {
/// enum Subcommand {
/// Variant1(EmptyVariant),
/// Variant2(EmptyVariant),
/// }
///
/// substrate_cli_subcommands!(
/// Subcommand => Variant1, Variant2
/// );
///
/// # use sc_cli::CliConfiguration;
/// # assert_eq!(Subcommand::Variant1(EmptyVariant {}).chain_id(false).unwrap(), "test-chain-id");
///
/// # }
/// ```
///
/// Which will expand to:
///
/// ```ignore
/// impl CliConfiguration for Subcommand {
/// fn base_path(&self) -> Result<Option<PathBuf>> {
/// match self {
/// Subcommand::Variant1(cmd) => cmd.base_path(),
/// Subcommand::Variant2(cmd) => cmd.base_path(),
/// }
/// }
///
/// fn is_dev(&self) -> Result<bool> {
/// match self {
/// Subcommand::Variant1(cmd) => cmd.is_dev(),
/// Subcommand::Variant2(cmd) => cmd.is_dev(),
/// }
/// }
///
/// // ...
/// }
/// ```
#[macro_export]
macro_rules! substrate_cli_subcommands {
($enum:ident => $($variant:ident),*) => {
impl $crate::CliConfiguration for $enum {
fn shared_params(&self) -> &$crate::SharedParams {
match self {
$($enum::$variant(cmd) => cmd.shared_params()),*
}
}
Cecile Tonglet
committed
Cecile Tonglet
committed
fn import_params(&self) -> Option<&$crate::ImportParams> {
match self {
$($enum::$variant(cmd) => cmd.import_params()),*
}
}
Cecile Tonglet
committed
Cecile Tonglet
committed
fn pruning_params(&self) -> Option<&$crate::PruningParams> {
match self {
$($enum::$variant(cmd) => cmd.pruning_params()),*
}
}
fn keystore_params(&self) -> Option<&$crate::KeystoreParams> {
match self {
$($enum::$variant(cmd) => cmd.keystore_params()),*
}
}
fn network_params(&self) -> Option<&$crate::NetworkParams> {
match self {
$($enum::$variant(cmd) => cmd.network_params()),*
}
}
fn offchain_worker_params(&self) -> Option<&$crate::OffchainWorkerParams> {
match self {
$($enum::$variant(cmd) => cmd.offchain_worker_params()),*
}
}
fn database_params(&self) -> Option<&$crate::DatabaseParams> {
match self {
$($enum::$variant(cmd) => cmd.database_params()),*
}
}
Cecile Tonglet
committed
fn base_path(&self) -> $crate::Result<::std::option::Option<sc_service::config::BasePath>> {
Cecile Tonglet
committed
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
match self {
$($enum::$variant(cmd) => cmd.base_path()),*
}
}
fn is_dev(&self) -> $crate::Result<bool> {
match self {
$($enum::$variant(cmd) => cmd.is_dev()),*
}
}
fn role(&self, is_dev: bool) -> $crate::Result<::sc_service::Role> {
match self {
$($enum::$variant(cmd) => cmd.role(is_dev)),*
}
}
fn transaction_pool(&self)
-> $crate::Result<::sc_service::config::TransactionPoolOptions> {
match self {
$($enum::$variant(cmd) => cmd.transaction_pool()),*
}
}
fn network_config(
&self,
chain_spec: &std::boxed::Box<dyn sc_service::ChainSpec>,
Cecile Tonglet
committed
is_dev: bool,
net_config_dir: std::path::PathBuf,
Cecile Tonglet
committed
client_id: &str,
node_name: &str,
node_key: sc_service::config::NodeKeyConfig,
default_listen_port: u16,
Cecile Tonglet
committed
) -> $crate::Result<::sc_service::config::NetworkConfiguration> {
match self {
$(
$enum::$variant(cmd) => cmd.network_config(
chain_spec,
is_dev,
net_config_dir,
client_id,
node_name,
node_key,
default_listen_port,
Cecile Tonglet
committed
)
),*
}
}
fn keystore_config(&self, base_path: &::std::path::PathBuf)
-> $crate::Result<::sc_service::config::KeystoreConfig> {
match self {
$($enum::$variant(cmd) => cmd.keystore_config(base_path)),*
}
}
fn database_cache_size(&self) -> $crate::Result<::std::option::Option<usize>> {
match self {
$($enum::$variant(cmd) => cmd.database_cache_size()),*
}
}
fn database_config(
&self,
base_path: &::std::path::PathBuf,
cache_size: usize,
Cecile Tonglet
committed
) -> $crate::Result<::sc_service::config::DatabaseConfig> {
match self {
$($enum::$variant(cmd) => cmd.database_config(base_path, cache_size, database)),*
}
}
fn database(&self) -> $crate::Result<::std::option::Option<$crate::Database>> {
match self {
$($enum::$variant(cmd) => cmd.database()),*
Cecile Tonglet
committed
}
}
fn state_cache_size(&self) -> $crate::Result<usize> {
match self {
$($enum::$variant(cmd) => cmd.state_cache_size()),*
}
}
fn state_cache_child_ratio(&self) -> $crate::Result<::std::option::Option<usize>> {
match self {
$($enum::$variant(cmd) => cmd.state_cache_child_ratio()),*
}
}
fn pruning(&self, unsafe_pruning: bool, role: &::sc_service::Role)
Cecile Tonglet
committed
-> $crate::Result<::sc_service::config::PruningMode> {
match self {
$($enum::$variant(cmd) => cmd.pruning(unsafe_pruning, role)),*
Cecile Tonglet
committed
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
}
}
fn chain_id(&self, is_dev: bool) -> $crate::Result<String> {
match self {
$($enum::$variant(cmd) => cmd.chain_id(is_dev)),*
}
}
fn init<C: $crate::SubstrateCli>(&self) -> $crate::Result<()> {
match self {
$($enum::$variant(cmd) => cmd.init::<C>()),*
}
}
fn node_name(&self) -> $crate::Result<String> {
match self {
$($enum::$variant(cmd) => cmd.node_name()),*
}
}
fn wasm_method(&self) -> $crate::Result<::sc_service::config::WasmExecutionMethod> {
match self {
$($enum::$variant(cmd) => cmd.wasm_method()),*
}
}
Cecile Tonglet
committed
André Silva
committed
fn execution_strategies(&self, is_dev: bool, is_validator: bool)
-> $crate::Result<::sc_client_api::execution_extensions::ExecutionStrategies> {
Cecile Tonglet
committed
match self {
André Silva
committed
$($enum::$variant(cmd) => cmd.execution_strategies(is_dev, is_validator)),*
Cecile Tonglet
committed
}
}
fn rpc_ipc(&self) -> $crate::Result<::std::option::Option<::std::string::String>> {
match self {
$($enum::$variant(cmd) => cmd.rpc_ipc()),*
}
}
fn rpc_http(
&self,
default_listen_port: u16,
) -> $crate::Result<std::option::Option<std::net::SocketAddr>> {
Cecile Tonglet
committed
match self {
$($enum::$variant(cmd) => cmd.rpc_http(default_listen_port)),*
Cecile Tonglet
committed
}
}
fn rpc_ws(
&self,
default_listen_port: u16,
) -> $crate::Result<std::option::Option<std::net::SocketAddr>> {
Cecile Tonglet
committed
match self {
$($enum::$variant(cmd) => cmd.rpc_ws(default_listen_port)),*
Cecile Tonglet
committed
}
}
fn rpc_methods(&self) -> $crate::Result<sc_service::config::RpcMethods> {
$($enum::$variant(cmd) => cmd.rpc_methods()),*
Cecile Tonglet
committed
fn rpc_ws_max_connections(&self) -> $crate::Result<::std::option::Option<usize>> {
match self {
$($enum::$variant(cmd) => cmd.rpc_ws_max_connections()),*
}
}
fn rpc_cors(&self, is_dev: bool)
-> $crate::Result<std::option::Option<std::vec::Vec<String>>> {
Cecile Tonglet
committed
match self {
$($enum::$variant(cmd) => cmd.rpc_cors(is_dev)),*
}
}
fn prometheus_config(&self, default_listen_port: u16)
-> $crate::Result<std::option::Option<sc_service::config::PrometheusConfig>> {
Cecile Tonglet
committed
match self {
$($enum::$variant(cmd) => cmd.prometheus_config(default_listen_port)),*
Cecile Tonglet
committed
}
}
fn telemetry_endpoints(
&self,
chain_spec: &Box<dyn sc_service::ChainSpec>,
) -> $crate::Result<std::option::Option<sc_service::config::TelemetryEndpoints>> {
Cecile Tonglet
committed
match self {
$($enum::$variant(cmd) => cmd.telemetry_endpoints(chain_spec)),*
}
}
fn telemetry_external_transport(&self)
-> $crate::Result<::std::option::Option<::sc_service::config::ExtTransport>> {
match self {
$($enum::$variant(cmd) => cmd.telemetry_external_transport()),*
}
}
fn default_heap_pages(&self) -> $crate::Result<::std::option::Option<u64>> {
match self {
$($enum::$variant(cmd) => cmd.default_heap_pages()),*
}
}
fn offchain_worker(
&self,
role: &::sc_service::Role,
) -> $crate::Result<::sc_service::config::OffchainWorkerConfig> {
Cecile Tonglet
committed
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
match self {
$($enum::$variant(cmd) => cmd.offchain_worker(role)),*
}
}
fn force_authoring(&self) -> $crate::Result<bool> {
match self {
$($enum::$variant(cmd) => cmd.force_authoring()),*
}
}
fn disable_grandpa(&self) -> $crate::Result<bool> {
match self {
$($enum::$variant(cmd) => cmd.disable_grandpa()),*
}
}
fn dev_key_seed(&self, is_dev: bool) -> $crate::Result<::std::option::Option<String>> {
match self {
$($enum::$variant(cmd) => cmd.dev_key_seed(is_dev)),*
}
}
fn tracing_targets(&self) -> $crate::Result<::std::option::Option<String>> {
match self {
$($enum::$variant(cmd) => cmd.tracing_targets()),*
}
}
fn tracing_receiver(&self) -> $crate::Result<::sc_service::TracingReceiver> {
match self {
$($enum::$variant(cmd) => cmd.tracing_receiver()),*
}
}
fn node_key(&self, net_config_dir: &::std::path::PathBuf)
-> $crate::Result<::sc_service::config::NodeKeyConfig> {
match self {
$($enum::$variant(cmd) => cmd.node_key(net_config_dir)),*
}
}
fn max_runtime_instances(&self) -> $crate::Result<::std::option::Option<usize>> {
match self {
$($enum::$variant(cmd) => cmd.max_runtime_instances()),*
}
}
fn log_filters(&self) -> $crate::Result<String> {
Cecile Tonglet
committed
match self {
$($enum::$variant(cmd) => cmd.log_filters()),*
}
}
}
Cecile Tonglet
committed
}
}
Cecile Tonglet
committed
substrate_cli_subcommands!(
Subcommand =>
BuildSpec,
ExportBlocks,
ExportState,
ImportBlocks,
CheckBlock,
Revert,
PurgeChain