mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 17:41:01 +00:00
Shared params in CLI API (#4466)
* Common shared parames getter * Expose more types from `service-builder` Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
committed by
Bastian Köcher
parent
bfad5f3ffc
commit
9950ea98fc
@@ -21,7 +21,7 @@ use sc_cli::{IntoExit, NoCustom, SharedParams, ImportParams, error};
|
|||||||
use sc_service::{AbstractService, Roles as ServiceRoles, Configuration};
|
use sc_service::{AbstractService, Roles as ServiceRoles, Configuration};
|
||||||
use log::info;
|
use log::info;
|
||||||
use structopt::{StructOpt, clap::App};
|
use structopt::{StructOpt, clap::App};
|
||||||
use sc_cli::{display_role, parse_and_prepare, AugmentClap, GetLogFilter, ParseAndPrepare};
|
use sc_cli::{display_role, parse_and_prepare, AugmentClap, GetSharedParams, ParseAndPrepare};
|
||||||
use crate::{service, ChainSpec, load_spec};
|
use crate::{service, ChainSpec, load_spec};
|
||||||
use crate::factory_impl::FactoryState;
|
use crate::factory_impl::FactoryState;
|
||||||
use node_transaction_factory::RuntimeAdapter;
|
use node_transaction_factory::RuntimeAdapter;
|
||||||
@@ -38,9 +38,11 @@ pub enum CustomSubcommands {
|
|||||||
Factory(FactoryCmd),
|
Factory(FactoryCmd),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetLogFilter for CustomSubcommands {
|
impl GetSharedParams for CustomSubcommands {
|
||||||
fn get_log_filter(&self) -> Option<String> {
|
fn shared_params(&self) -> Option<&SharedParams> {
|
||||||
None
|
match self {
|
||||||
|
CustomSubcommands::Factory(cmd) => Some(&cmd.shared_params),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ use params::{
|
|||||||
NodeKeyParams, NodeKeyType, Cors, CheckBlockCmd,
|
NodeKeyParams, NodeKeyType, Cors, CheckBlockCmd,
|
||||||
};
|
};
|
||||||
pub use params::{NoCustom, CoreParams, SharedParams, ImportParams, ExecutionStrategy};
|
pub use params::{NoCustom, CoreParams, SharedParams, ImportParams, ExecutionStrategy};
|
||||||
pub use traits::{GetLogFilter, AugmentClap};
|
pub use traits::{GetSharedParams, AugmentClap};
|
||||||
use app_dirs::{AppInfo, AppDataType};
|
use app_dirs::{AppInfo, AppDataType};
|
||||||
use log::info;
|
use log::info;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
@@ -195,7 +195,7 @@ pub fn parse_and_prepare<'a, CC, RP, I>(
|
|||||||
args: I,
|
args: I,
|
||||||
) -> ParseAndPrepare<'a, CC, RP>
|
) -> ParseAndPrepare<'a, CC, RP>
|
||||||
where
|
where
|
||||||
CC: StructOpt + Clone + GetLogFilter,
|
CC: StructOpt + Clone + GetSharedParams,
|
||||||
RP: StructOpt + Clone + AugmentClap,
|
RP: StructOpt + Clone + AugmentClap,
|
||||||
I: IntoIterator,
|
I: IntoIterator,
|
||||||
<I as IntoIterator>::Item: Into<std::ffi::OsString> + Clone,
|
<I as IntoIterator>::Item: Into<std::ffi::OsString> + Clone,
|
||||||
@@ -216,10 +216,9 @@ where
|
|||||||
.setting(AppSettings::SubcommandsNegateReqs)
|
.setting(AppSettings::SubcommandsNegateReqs)
|
||||||
.get_matches_from(args);
|
.get_matches_from(args);
|
||||||
let cli_args = CoreParams::<CC, RP>::from_clap(&matches);
|
let cli_args = CoreParams::<CC, RP>::from_clap(&matches);
|
||||||
init_logger(cli_args.get_log_filter().as_ref().map(|v| v.as_ref()).unwrap_or(""));
|
|
||||||
fdlimit::raise_fd_limit();
|
fdlimit::raise_fd_limit();
|
||||||
|
|
||||||
match cli_args {
|
let args = match cli_args {
|
||||||
params::CoreParams::Run(params) => ParseAndPrepare::Run(
|
params::CoreParams::Run(params) => ParseAndPrepare::Run(
|
||||||
ParseAndPrepareRun { params, impl_name, version }
|
ParseAndPrepareRun { params, impl_name, version }
|
||||||
),
|
),
|
||||||
@@ -242,7 +241,9 @@ where
|
|||||||
ParseAndPrepareRevert { params, version }
|
ParseAndPrepareRevert { params, version }
|
||||||
),
|
),
|
||||||
params::CoreParams::Custom(params) => ParseAndPrepare::CustomCommand(params),
|
params::CoreParams::Custom(params) => ParseAndPrepare::CustomCommand(params),
|
||||||
}
|
};
|
||||||
|
init_logger(args.shared_params().and_then(|p| p.log.as_ref()).map(|v| v.as_ref()).unwrap_or(""));
|
||||||
|
args
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a string displaying the node role, special casing the sentry mode
|
/// Returns a string displaying the node role, special casing the sentry mode
|
||||||
@@ -277,6 +278,22 @@ pub enum ParseAndPrepare<'a, CC, RP> {
|
|||||||
CustomCommand(CC),
|
CustomCommand(CC),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, CC, RP> ParseAndPrepare<'a, CC, RP> where CC: GetSharedParams {
|
||||||
|
/// Return common set of parameters shared by all commands.
|
||||||
|
pub fn shared_params(&self) -> Option<&SharedParams> {
|
||||||
|
match self {
|
||||||
|
ParseAndPrepare::Run(c) => Some(&c.params.left.shared_params),
|
||||||
|
ParseAndPrepare::BuildSpec(c) => Some(&c.params.shared_params),
|
||||||
|
ParseAndPrepare::ExportBlocks(c) => Some(&c.params.shared_params),
|
||||||
|
ParseAndPrepare::ImportBlocks(c) => Some(&c.params.shared_params),
|
||||||
|
ParseAndPrepare::CheckBlock(c) => Some(&c.params.shared_params),
|
||||||
|
ParseAndPrepare::PurgeChain(c) => Some(&c.params.shared_params),
|
||||||
|
ParseAndPrepare::RevertChain(c) => Some(&c.params.shared_params),
|
||||||
|
ParseAndPrepare::CustomCommand(c) => c.shared_params(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Command ready to run the main client.
|
/// Command ready to run the main client.
|
||||||
pub struct ParseAndPrepareRun<'a, RP> {
|
pub struct ParseAndPrepareRun<'a, RP> {
|
||||||
params: MergeParameters<RunCmd, RP>,
|
params: MergeParameters<RunCmd, RP>,
|
||||||
|
|||||||
@@ -14,24 +14,13 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::traits::{AugmentClap, GetLogFilter};
|
use crate::traits::{AugmentClap, GetSharedParams};
|
||||||
|
|
||||||
use std::{str::FromStr, path::PathBuf};
|
use std::{str::FromStr, path::PathBuf};
|
||||||
use structopt::{StructOpt, clap::{arg_enum, App, AppSettings, SubCommand, Arg}};
|
use structopt::{StructOpt, clap::{arg_enum, App, AppSettings, SubCommand, Arg}};
|
||||||
|
|
||||||
pub use crate::execution_strategy::ExecutionStrategy;
|
pub use crate::execution_strategy::ExecutionStrategy;
|
||||||
|
|
||||||
/// Auxiliary macro to implement `GetLogFilter` for all types that have the `shared_params` field.
|
|
||||||
macro_rules! impl_get_log_filter {
|
|
||||||
( $type:ident ) => {
|
|
||||||
impl $crate::GetLogFilter for $type {
|
|
||||||
fn get_log_filter(&self) -> Option<String> {
|
|
||||||
self.shared_params.get_log_filter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<sc_client_api::ExecutionStrategy> for ExecutionStrategy {
|
impl Into<sc_client_api::ExecutionStrategy> for ExecutionStrategy {
|
||||||
fn into(self) -> sc_client_api::ExecutionStrategy {
|
fn into(self) -> sc_client_api::ExecutionStrategy {
|
||||||
match self {
|
match self {
|
||||||
@@ -153,12 +142,6 @@ pub struct ImportParams {
|
|||||||
pub state_cache_size: usize,
|
pub state_cache_size: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetLogFilter for SharedParams {
|
|
||||||
fn get_log_filter(&self) -> Option<String> {
|
|
||||||
self.log.clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parameters used to create the network configuration.
|
/// Parameters used to create the network configuration.
|
||||||
#[derive(Debug, StructOpt, Clone)]
|
#[derive(Debug, StructOpt, Clone)]
|
||||||
pub struct NetworkConfigurationParams {
|
pub struct NetworkConfigurationParams {
|
||||||
@@ -723,7 +706,6 @@ fn parse_cors(s: &str) -> Result<Cors, Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl_augment_clap!(RunCmd);
|
impl_augment_clap!(RunCmd);
|
||||||
impl_get_log_filter!(RunCmd);
|
|
||||||
|
|
||||||
/// The `build-spec` command used to build a specification.
|
/// The `build-spec` command used to build a specification.
|
||||||
#[derive(Debug, StructOpt, Clone)]
|
#[derive(Debug, StructOpt, Clone)]
|
||||||
@@ -748,8 +730,6 @@ pub struct BuildSpecCmd {
|
|||||||
pub node_key_params: NodeKeyParams,
|
pub node_key_params: NodeKeyParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_get_log_filter!(BuildSpecCmd);
|
|
||||||
|
|
||||||
/// Wrapper type of `String` which holds an arbitary sized unsigned integer formatted as decimal.
|
/// Wrapper type of `String` which holds an arbitary sized unsigned integer formatted as decimal.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct BlockNumber(String);
|
pub struct BlockNumber(String);
|
||||||
@@ -813,8 +793,6 @@ pub struct ExportBlocksCmd {
|
|||||||
pub shared_params: SharedParams,
|
pub shared_params: SharedParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_get_log_filter!(ExportBlocksCmd);
|
|
||||||
|
|
||||||
/// The `import-blocks` command used to import blocks.
|
/// The `import-blocks` command used to import blocks.
|
||||||
#[derive(Debug, StructOpt, Clone)]
|
#[derive(Debug, StructOpt, Clone)]
|
||||||
pub struct ImportBlocksCmd {
|
pub struct ImportBlocksCmd {
|
||||||
@@ -837,8 +815,6 @@ pub struct ImportBlocksCmd {
|
|||||||
pub import_params: ImportParams,
|
pub import_params: ImportParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_get_log_filter!(ImportBlocksCmd);
|
|
||||||
|
|
||||||
/// The `check-block` command used to validate blocks.
|
/// The `check-block` command used to validate blocks.
|
||||||
#[derive(Debug, StructOpt, Clone)]
|
#[derive(Debug, StructOpt, Clone)]
|
||||||
pub struct CheckBlockCmd {
|
pub struct CheckBlockCmd {
|
||||||
@@ -861,8 +837,6 @@ pub struct CheckBlockCmd {
|
|||||||
pub import_params: ImportParams,
|
pub import_params: ImportParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_get_log_filter!(CheckBlockCmd);
|
|
||||||
|
|
||||||
/// The `revert` command used revert the chain to a previous state.
|
/// The `revert` command used revert the chain to a previous state.
|
||||||
#[derive(Debug, StructOpt, Clone)]
|
#[derive(Debug, StructOpt, Clone)]
|
||||||
pub struct RevertCmd {
|
pub struct RevertCmd {
|
||||||
@@ -875,8 +849,6 @@ pub struct RevertCmd {
|
|||||||
pub shared_params: SharedParams,
|
pub shared_params: SharedParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_get_log_filter!(RevertCmd);
|
|
||||||
|
|
||||||
/// The `purge-chain` command used to remove the whole chain.
|
/// The `purge-chain` command used to remove the whole chain.
|
||||||
#[derive(Debug, StructOpt, Clone)]
|
#[derive(Debug, StructOpt, Clone)]
|
||||||
pub struct PurgeChainCmd {
|
pub struct PurgeChainCmd {
|
||||||
@@ -889,8 +861,6 @@ pub struct PurgeChainCmd {
|
|||||||
pub shared_params: SharedParams,
|
pub shared_params: SharedParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_get_log_filter!(PurgeChainCmd);
|
|
||||||
|
|
||||||
/// All core commands that are provided by default.
|
/// All core commands that are provided by default.
|
||||||
///
|
///
|
||||||
/// The core commands are split into multiple subcommands and `Run` is the default subcommand. From
|
/// The core commands are split into multiple subcommands and `Run` is the default subcommand. From
|
||||||
@@ -924,7 +894,7 @@ pub enum CoreParams<CC, RP> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<CC, RP> StructOpt for CoreParams<CC, RP> where
|
impl<CC, RP> StructOpt for CoreParams<CC, RP> where
|
||||||
CC: StructOpt + GetLogFilter,
|
CC: StructOpt + GetSharedParams,
|
||||||
RP: StructOpt + AugmentClap
|
RP: StructOpt + AugmentClap
|
||||||
{
|
{
|
||||||
fn clap<'a, 'b>() -> App<'a, 'b> {
|
fn clap<'a, 'b>() -> App<'a, 'b> {
|
||||||
@@ -979,21 +949,6 @@ impl<CC, RP> StructOpt for CoreParams<CC, RP> where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<CC, RP> GetLogFilter for CoreParams<CC, RP> where CC: GetLogFilter {
|
|
||||||
fn get_log_filter(&self) -> Option<String> {
|
|
||||||
match self {
|
|
||||||
CoreParams::Run(c) => c.left.get_log_filter(),
|
|
||||||
CoreParams::BuildSpec(c) => c.get_log_filter(),
|
|
||||||
CoreParams::ExportBlocks(c) => c.get_log_filter(),
|
|
||||||
CoreParams::ImportBlocks(c) => c.get_log_filter(),
|
|
||||||
CoreParams::CheckBlock(c) => c.get_log_filter(),
|
|
||||||
CoreParams::PurgeChain(c) => c.get_log_filter(),
|
|
||||||
CoreParams::Revert(c) => c.get_log_filter(),
|
|
||||||
CoreParams::Custom(c) => c.get_log_filter(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A special commandline parameter that expands to nothing.
|
/// A special commandline parameter that expands to nothing.
|
||||||
/// Should be used as custom subcommand/run arguments if no custom values are required.
|
/// Should be used as custom subcommand/run arguments if no custom values are required.
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
@@ -1015,8 +970,8 @@ impl AugmentClap for NoCustom {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetLogFilter for NoCustom {
|
impl GetSharedParams for NoCustom {
|
||||||
fn get_log_filter(&self) -> Option<String> {
|
fn shared_params(&self) -> Option<&SharedParams> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use structopt::{StructOpt, clap::App};
|
use structopt::{StructOpt, clap::App};
|
||||||
|
use crate::params::SharedParams;
|
||||||
|
|
||||||
/// Something that can augment a clap app with further parameters.
|
/// Something that can augment a clap app with further parameters.
|
||||||
/// `derive(StructOpt)` is implementing this function by default, so a macro `impl_augment_clap!`
|
/// `derive(StructOpt)` is implementing this function by default, so a macro `impl_augment_clap!`
|
||||||
@@ -37,8 +38,8 @@ macro_rules! impl_augment_clap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the log filter given by the user as commandline argument.
|
/// Supports getting common params.
|
||||||
pub trait GetLogFilter {
|
pub trait GetSharedParams {
|
||||||
/// Returns the set log filter.
|
/// Returns shared params if any.
|
||||||
fn get_log_filter(&self) -> Option<String>;
|
fn shared_params(&self) -> Option<&SharedParams>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ pub struct ServiceBuilder<TBl, TRtApi, TCfg, TGen, TCSExt, TCl, TFchr, TSc, TImp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Full client type.
|
/// Full client type.
|
||||||
type TFullClient<TBl, TRtApi, TExecDisp> = Client<
|
pub type TFullClient<TBl, TRtApi, TExecDisp> = Client<
|
||||||
TFullBackend<TBl>,
|
TFullBackend<TBl>,
|
||||||
TFullCallExecutor<TBl, TExecDisp>,
|
TFullCallExecutor<TBl, TExecDisp>,
|
||||||
TBl,
|
TBl,
|
||||||
@@ -103,16 +103,16 @@ type TFullClient<TBl, TRtApi, TExecDisp> = Client<
|
|||||||
>;
|
>;
|
||||||
|
|
||||||
/// Full client backend type.
|
/// Full client backend type.
|
||||||
type TFullBackend<TBl> = sc_client_db::Backend<TBl>;
|
pub type TFullBackend<TBl> = sc_client_db::Backend<TBl>;
|
||||||
|
|
||||||
/// Full client call executor type.
|
/// Full client call executor type.
|
||||||
type TFullCallExecutor<TBl, TExecDisp> = sc_client::LocalCallExecutor<
|
pub type TFullCallExecutor<TBl, TExecDisp> = sc_client::LocalCallExecutor<
|
||||||
sc_client_db::Backend<TBl>,
|
sc_client_db::Backend<TBl>,
|
||||||
NativeExecutor<TExecDisp>,
|
NativeExecutor<TExecDisp>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/// Light client type.
|
/// Light client type.
|
||||||
type TLightClient<TBl, TRtApi, TExecDisp> = Client<
|
pub type TLightClient<TBl, TRtApi, TExecDisp> = Client<
|
||||||
TLightBackend<TBl>,
|
TLightBackend<TBl>,
|
||||||
TLightCallExecutor<TBl, TExecDisp>,
|
TLightCallExecutor<TBl, TExecDisp>,
|
||||||
TBl,
|
TBl,
|
||||||
@@ -120,13 +120,13 @@ type TLightClient<TBl, TRtApi, TExecDisp> = Client<
|
|||||||
>;
|
>;
|
||||||
|
|
||||||
/// Light client backend type.
|
/// Light client backend type.
|
||||||
type TLightBackend<TBl> = sc_client::light::backend::Backend<
|
pub type TLightBackend<TBl> = sc_client::light::backend::Backend<
|
||||||
sc_client_db::light::LightStorage<TBl>,
|
sc_client_db::light::LightStorage<TBl>,
|
||||||
Blake2Hasher,
|
Blake2Hasher,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/// Light call executor type.
|
/// Light call executor type.
|
||||||
type TLightCallExecutor<TBl, TExecDisp> = sc_client::light::call_executor::GenesisCallExecutor<
|
pub type TLightCallExecutor<TBl, TExecDisp> = sc_client::light::call_executor::GenesisCallExecutor<
|
||||||
sc_client::light::backend::Backend<
|
sc_client::light::backend::Backend<
|
||||||
sc_client_db::light::LightStorage<TBl>,
|
sc_client_db::light::LightStorage<TBl>,
|
||||||
Blake2Hasher
|
Blake2Hasher
|
||||||
|
|||||||
@@ -53,7 +53,10 @@ use sp_runtime::generic::BlockId;
|
|||||||
use sp_runtime::traits::{NumberFor, Block as BlockT};
|
use sp_runtime::traits::{NumberFor, Block as BlockT};
|
||||||
|
|
||||||
pub use self::error::Error;
|
pub use self::error::Error;
|
||||||
pub use self::builder::{ServiceBuilder, ServiceBuilderCommand};
|
pub use self::builder::{
|
||||||
|
ServiceBuilder, ServiceBuilderCommand, TFullClient, TLightClient, TFullBackend, TLightBackend,
|
||||||
|
TFullCallExecutor, TLightCallExecutor,
|
||||||
|
};
|
||||||
pub use config::{Configuration, Roles, PruningMode};
|
pub use config::{Configuration, Roles, PruningMode};
|
||||||
pub use sc_chain_spec::{ChainSpec, Properties, RuntimeGenesis, Extension as ChainSpecExtension};
|
pub use sc_chain_spec::{ChainSpec, Properties, RuntimeGenesis, Extension as ChainSpecExtension};
|
||||||
pub use sp_transaction_pool::{TransactionPool, TransactionPoolMaintainer, InPoolTransaction, error::IntoPoolError};
|
pub use sp_transaction_pool::{TransactionPool, TransactionPoolMaintainer, InPoolTransaction, error::IntoPoolError};
|
||||||
|
|||||||
Reference in New Issue
Block a user