mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 16:57:58 +00:00
use clap3 instead of structopt (#10632)
* use clap3 instead of structopt Signed-off-by: koushiro <koushiro.cqx@gmail.com> * format Signed-off-by: koushiro <koushiro.cqx@gmail.com> * update ss58-registry and revert some nits Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Fix clippy and doc Signed-off-by: koushiro <koushiro.cqx@gmail.com> * update clap to 3.0.7 Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Apply review suggestions Signed-off-by: koushiro <koushiro.cqx@gmail.com> * remove useless option long name Signed-off-by: koushiro <koushiro.cqx@gmail.com> * cargo fmt Signed-off-by: koushiro <koushiro.cqx@gmail.com>
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
// NOTE: we allow missing docs here because arg_enum! creates the function variants without doc
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use structopt::clap::arg_enum;
|
||||
use clap::ArgEnum;
|
||||
|
||||
/// How to execute Wasm runtime code.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
@@ -86,12 +86,11 @@ impl Into<sc_service::config::WasmExecutionMethod> for WasmExecutionMethod {
|
||||
}
|
||||
}
|
||||
|
||||
arg_enum! {
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum TracingReceiver {
|
||||
Log,
|
||||
}
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, ArgEnum)]
|
||||
#[clap(rename_all = "PascalCase")]
|
||||
pub enum TracingReceiver {
|
||||
Log,
|
||||
}
|
||||
|
||||
impl Into<sc_tracing::TracingReceiver> for TracingReceiver {
|
||||
@@ -102,44 +101,40 @@ impl Into<sc_tracing::TracingReceiver> for TracingReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
arg_enum! {
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum NodeKeyType {
|
||||
Ed25519
|
||||
}
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, ArgEnum)]
|
||||
#[clap(rename_all = "PascalCase")]
|
||||
pub enum NodeKeyType {
|
||||
Ed25519,
|
||||
}
|
||||
|
||||
arg_enum! {
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum CryptoScheme {
|
||||
Ed25519,
|
||||
Sr25519,
|
||||
Ecdsa,
|
||||
}
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, ArgEnum)]
|
||||
#[clap(rename_all = "PascalCase")]
|
||||
pub enum CryptoScheme {
|
||||
Ed25519,
|
||||
Sr25519,
|
||||
Ecdsa,
|
||||
}
|
||||
|
||||
arg_enum! {
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum OutputType {
|
||||
Json,
|
||||
Text,
|
||||
}
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, ArgEnum)]
|
||||
#[clap(rename_all = "PascalCase")]
|
||||
pub enum OutputType {
|
||||
Json,
|
||||
Text,
|
||||
}
|
||||
|
||||
arg_enum! {
|
||||
/// How to execute blocks
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ExecutionStrategy {
|
||||
// Execute with native build (if available, WebAssembly otherwise).
|
||||
Native,
|
||||
// Only execute with the WebAssembly build.
|
||||
Wasm,
|
||||
// Execute with both native (where available) and WebAssembly builds.
|
||||
Both,
|
||||
// Execute with the native build if possible; if it fails, then execute with WebAssembly.
|
||||
NativeElseWasm,
|
||||
}
|
||||
/// How to execute blocks
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, ArgEnum)]
|
||||
#[clap(rename_all = "PascalCase")]
|
||||
pub enum ExecutionStrategy {
|
||||
// Execute with native build (if available, WebAssembly otherwise).
|
||||
Native,
|
||||
// Only execute with the WebAssembly build.
|
||||
Wasm,
|
||||
// Execute with both native (where available) and WebAssembly builds.
|
||||
Both,
|
||||
// Execute with the native build if possible; if it fails, then execute with WebAssembly.
|
||||
NativeElseWasm,
|
||||
}
|
||||
|
||||
impl Into<sc_client_api::ExecutionStrategy> for ExecutionStrategy {
|
||||
@@ -165,19 +160,18 @@ impl ExecutionStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
arg_enum! {
|
||||
/// Available RPC methods.
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub enum RpcMethods {
|
||||
// Expose every RPC method only when RPC is listening on `localhost`,
|
||||
// otherwise serve only safe RPC methods.
|
||||
Auto,
|
||||
// Allow only a safe subset of RPC methods.
|
||||
Safe,
|
||||
// Expose every RPC method (even potentially unsafe ones).
|
||||
Unsafe,
|
||||
}
|
||||
/// Available RPC methods.
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, ArgEnum)]
|
||||
#[clap(rename_all = "PascalCase")]
|
||||
pub enum RpcMethods {
|
||||
// Expose every RPC method only when RPC is listening on `localhost`,
|
||||
// otherwise serve only safe RPC methods.
|
||||
Auto,
|
||||
// Allow only a safe subset of RPC methods.
|
||||
Safe,
|
||||
// Expose every RPC method (even potentially unsafe ones).
|
||||
Unsafe,
|
||||
}
|
||||
|
||||
impl Into<sc_service::config::RpcMethods> for RpcMethods {
|
||||
@@ -225,31 +219,28 @@ impl Database {
|
||||
}
|
||||
}
|
||||
|
||||
arg_enum! {
|
||||
/// Whether off-chain workers are enabled.
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum OffchainWorkerEnabled {
|
||||
Always,
|
||||
Never,
|
||||
WhenValidating,
|
||||
}
|
||||
/// Whether off-chain workers are enabled.
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Debug, Clone, ArgEnum)]
|
||||
#[clap(rename_all = "PascalCase")]
|
||||
pub enum OffchainWorkerEnabled {
|
||||
Always,
|
||||
Never,
|
||||
WhenValidating,
|
||||
}
|
||||
|
||||
arg_enum! {
|
||||
/// Syncing mode.
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum SyncMode {
|
||||
// Full sync. Donwnload end verify all blocks.
|
||||
Full,
|
||||
// Download blocks without executing them. Download latest state with proofs.
|
||||
Fast,
|
||||
// Download blocks without executing them. Download latest state without proofs.
|
||||
FastUnsafe,
|
||||
// Prove finality and download the latest state.
|
||||
Warp,
|
||||
}
|
||||
/// Syncing mode.
|
||||
#[derive(Debug, Clone, Copy, ArgEnum)]
|
||||
#[clap(rename_all = "PascalCase")]
|
||||
pub enum SyncMode {
|
||||
// Full sync. Donwnload end verify all blocks.
|
||||
Full,
|
||||
// Download blocks without executing them. Download latest state with proofs.
|
||||
Fast,
|
||||
// Download blocks without executing them. Download latest state without proofs.
|
||||
FastUnsafe,
|
||||
// Prove finality and download the latest state.
|
||||
Warp,
|
||||
}
|
||||
|
||||
impl Into<sc_network::config::SyncMode> for SyncMode {
|
||||
|
||||
@@ -21,6 +21,7 @@ use crate::{
|
||||
params::{NodeKeyParams, SharedParams},
|
||||
CliConfiguration,
|
||||
};
|
||||
use clap::Parser;
|
||||
use log::info;
|
||||
use sc_network::config::build_multiaddr;
|
||||
use sc_service::{
|
||||
@@ -28,28 +29,27 @@ use sc_service::{
|
||||
ChainSpec,
|
||||
};
|
||||
use std::io::Write;
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `build-spec` command used to build a specification.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
pub struct BuildSpecCmd {
|
||||
/// Force raw genesis storage output.
|
||||
#[structopt(long = "raw")]
|
||||
#[clap(long)]
|
||||
pub raw: bool,
|
||||
|
||||
/// Disable adding the default bootnode to the specification.
|
||||
///
|
||||
/// By default the `/ip4/127.0.0.1/tcp/30333/p2p/NODE_PEER_ID` bootnode is added to the
|
||||
/// specification when no bootnode exists.
|
||||
#[structopt(long = "disable-default-bootnode")]
|
||||
#[clap(long)]
|
||||
pub disable_default_bootnode: bool,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub shared_params: SharedParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub node_key_params: NodeKeyParams,
|
||||
}
|
||||
|
||||
|
||||
@@ -21,30 +21,30 @@ use crate::{
|
||||
params::{BlockNumberOrHash, ImportParams, SharedParams},
|
||||
CliConfiguration,
|
||||
};
|
||||
use clap::Parser;
|
||||
use sc_client_api::{BlockBackend, HeaderBackend};
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
|
||||
use std::{fmt::Debug, str::FromStr, sync::Arc};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `check-block` command used to validate blocks.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
pub struct CheckBlockCmd {
|
||||
/// Block hash or number
|
||||
#[structopt(value_name = "HASH or NUMBER")]
|
||||
#[clap(value_name = "HASH or NUMBER")]
|
||||
pub input: BlockNumberOrHash,
|
||||
|
||||
/// The default number of 64KB pages to ever allocate for Wasm execution.
|
||||
///
|
||||
/// Don't alter this unless you know what you're doing.
|
||||
#[structopt(long = "default-heap-pages", value_name = "COUNT")]
|
||||
#[clap(long, value_name = "COUNT")]
|
||||
pub default_heap_pages: Option<u32>,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub shared_params: SharedParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub import_params: ImportParams,
|
||||
}
|
||||
|
||||
|
||||
@@ -21,46 +21,46 @@ use crate::{
|
||||
params::{DatabaseParams, GenericNumber, PruningParams, SharedParams},
|
||||
CliConfiguration,
|
||||
};
|
||||
use clap::Parser;
|
||||
use log::info;
|
||||
use sc_client_api::{BlockBackend, UsageProvider};
|
||||
use sc_service::{chain_ops::export_blocks, config::DatabaseSource};
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
|
||||
use std::{fmt::Debug, fs, io, path::PathBuf, str::FromStr, sync::Arc};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `export-blocks` command used to export blocks.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
pub struct ExportBlocksCmd {
|
||||
/// Output file name or stdout if unspecified.
|
||||
#[structopt(parse(from_os_str))]
|
||||
#[clap(parse(from_os_str))]
|
||||
pub output: Option<PathBuf>,
|
||||
|
||||
/// Specify starting block number.
|
||||
///
|
||||
/// Default is 1.
|
||||
#[structopt(long = "from", value_name = "BLOCK")]
|
||||
#[clap(long, value_name = "BLOCK")]
|
||||
pub from: Option<GenericNumber>,
|
||||
|
||||
/// Specify last block number.
|
||||
///
|
||||
/// Default is best block.
|
||||
#[structopt(long = "to", value_name = "BLOCK")]
|
||||
#[clap(long, value_name = "BLOCK")]
|
||||
pub to: Option<GenericNumber>,
|
||||
|
||||
/// Use binary output rather than JSON.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub binary: bool,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub shared_params: SharedParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub pruning_params: PruningParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub database_params: DatabaseParams,
|
||||
}
|
||||
|
||||
|
||||
@@ -21,26 +21,26 @@ use crate::{
|
||||
params::{BlockNumberOrHash, PruningParams, SharedParams},
|
||||
CliConfiguration,
|
||||
};
|
||||
use clap::Parser;
|
||||
use log::info;
|
||||
use sc_client_api::{StorageProvider, UsageProvider};
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
|
||||
use std::{fmt::Debug, io::Write, str::FromStr, sync::Arc};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `export-state` command used to export the state of a given block into
|
||||
/// a chain spec.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
pub struct ExportStateCmd {
|
||||
/// Block hash or number.
|
||||
#[structopt(value_name = "HASH or NUMBER")]
|
||||
#[clap(value_name = "HASH or NUMBER")]
|
||||
pub input: Option<BlockNumberOrHash>,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub shared_params: SharedParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub pruning_params: PruningParams,
|
||||
}
|
||||
|
||||
|
||||
@@ -21,30 +21,30 @@ use crate::{
|
||||
NetworkSchemeFlag, OutputTypeFlag,
|
||||
};
|
||||
use bip39::{Language, Mnemonic, MnemonicType};
|
||||
use structopt::StructOpt;
|
||||
use clap::Parser;
|
||||
|
||||
/// The `generate` command
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[structopt(name = "generate", about = "Generate a random account")]
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
#[clap(name = "generate", about = "Generate a random account")]
|
||||
pub struct GenerateCmd {
|
||||
/// The number of words in the phrase to generate. One of 12 (default), 15, 18, 21 and 24.
|
||||
#[structopt(long, short = "w", value_name = "WORDS")]
|
||||
#[clap(short = 'w', long, value_name = "WORDS")]
|
||||
words: Option<usize>,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub keystore_params: KeystoreParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub network_scheme: NetworkSchemeFlag,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub output_scheme: OutputTypeFlag,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub crypto_scheme: CryptoSchemeFlag,
|
||||
}
|
||||
|
||||
@@ -78,12 +78,11 @@ impl GenerateCmd {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::GenerateCmd;
|
||||
use structopt::StructOpt;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn generate() {
|
||||
let generate = GenerateCmd::from_iter(&["generate", "--password", "12345"]);
|
||||
let generate = GenerateCmd::parse_from(&["generate", "--password", "12345"]);
|
||||
assert!(generate.run().is_ok())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
//! Implementation of the `generate-node-key` subcommand
|
||||
|
||||
use crate::Error;
|
||||
use clap::Parser;
|
||||
use libp2p::identity::{ed25519 as libp2p_ed25519, PublicKey};
|
||||
use std::{fs, path::PathBuf};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `generate-node-key` command
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(
|
||||
name = "generate-node-key",
|
||||
about = "Generate a random node libp2p key, save it to \
|
||||
file or print it to stdout and print its peer ID to stderr"
|
||||
@@ -33,7 +33,7 @@ pub struct GenerateNodeKeyCmd {
|
||||
/// Name of file to save secret key to.
|
||||
///
|
||||
/// If not given, the secret key is printed to stdout.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
file: Option<PathBuf>,
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ mod tests {
|
||||
fn generate_node_key() {
|
||||
let mut file = Builder::new().prefix("keyfile").tempfile().unwrap();
|
||||
let file_path = file.path().display().to_string();
|
||||
let generate = GenerateNodeKeyCmd::from_iter(&["generate-node-key", "--file", &file_path]);
|
||||
let generate = GenerateNodeKeyCmd::parse_from(&["generate-node-key", "--file", &file_path]);
|
||||
assert!(generate.run().is_ok());
|
||||
let mut buf = String::new();
|
||||
assert!(file.read_to_string(&mut buf).is_ok());
|
||||
|
||||
@@ -21,6 +21,7 @@ use crate::{
|
||||
params::{ImportParams, SharedParams},
|
||||
CliConfiguration,
|
||||
};
|
||||
use clap::Parser;
|
||||
use sc_client_api::HeaderBackend;
|
||||
use sc_service::chain_ops::import_blocks;
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
@@ -31,31 +32,30 @@ use std::{
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `import-blocks` command used to import blocks.
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct ImportBlocksCmd {
|
||||
/// Input file or stdin if unspecified.
|
||||
#[structopt(parse(from_os_str))]
|
||||
#[clap(parse(from_os_str))]
|
||||
pub input: Option<PathBuf>,
|
||||
|
||||
/// The default number of 64KB pages to ever allocate for Wasm execution.
|
||||
///
|
||||
/// Don't alter this unless you know what you're doing.
|
||||
#[structopt(long = "default-heap-pages", value_name = "COUNT")]
|
||||
#[clap(long, value_name = "COUNT")]
|
||||
pub default_heap_pages: Option<u32>,
|
||||
|
||||
/// Try importing blocks from binary format rather than JSON.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub binary: bool,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub shared_params: SharedParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub import_params: ImportParams,
|
||||
}
|
||||
|
||||
|
||||
@@ -20,42 +20,37 @@
|
||||
use crate::{
|
||||
utils, with_crypto_scheme, CryptoScheme, Error, KeystoreParams, SharedParams, SubstrateCli,
|
||||
};
|
||||
use clap::Parser;
|
||||
use sc_keystore::LocalKeystore;
|
||||
use sc_service::config::{BasePath, KeystoreConfig};
|
||||
use sp_core::crypto::{KeyTypeId, SecretString};
|
||||
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
|
||||
use std::{convert::TryFrom, sync::Arc};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `insert` command
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[structopt(name = "insert", about = "Insert a key to the keystore of a node.")]
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
#[clap(name = "insert", about = "Insert a key to the keystore of a node.")]
|
||||
pub struct InsertKeyCmd {
|
||||
/// The secret key URI.
|
||||
/// If the value is a file, the file content is used as URI.
|
||||
/// If not given, you will be prompted for the URI.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
suri: Option<String>,
|
||||
|
||||
/// Key type, examples: "gran", or "imon"
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
key_type: String,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub shared_params: SharedParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub keystore_params: KeystoreParams,
|
||||
|
||||
/// The cryptography scheme that should be used to generate the key out of the given URI.
|
||||
#[structopt(
|
||||
long,
|
||||
value_name = "SCHEME",
|
||||
possible_values = &CryptoScheme::variants(),
|
||||
case_insensitive = true,
|
||||
)]
|
||||
#[clap(long, value_name = "SCHEME", arg_enum, ignore_case = true)]
|
||||
pub scheme: CryptoScheme,
|
||||
}
|
||||
|
||||
@@ -100,7 +95,6 @@ mod tests {
|
||||
use super::*;
|
||||
use sc_service::{ChainSpec, ChainType, GenericChainSpec, NoExtension};
|
||||
use sp_core::{sr25519::Pair, ByteArray, Pair as _};
|
||||
use structopt::StructOpt;
|
||||
use tempfile::TempDir;
|
||||
|
||||
struct Cli;
|
||||
@@ -156,7 +150,7 @@ mod tests {
|
||||
let path_str = format!("{}", path.path().display());
|
||||
let (key, uri, _) = Pair::generate_with_phrase(None);
|
||||
|
||||
let inspect = InsertKeyCmd::from_iter(&[
|
||||
let inspect = InsertKeyCmd::parse_from(&[
|
||||
"insert-key",
|
||||
"-d",
|
||||
&path_str,
|
||||
|
||||
@@ -21,13 +21,13 @@ use crate::{
|
||||
utils::{self, print_from_public, print_from_uri},
|
||||
with_crypto_scheme, CryptoSchemeFlag, Error, KeystoreParams, NetworkSchemeFlag, OutputTypeFlag,
|
||||
};
|
||||
use clap::Parser;
|
||||
use sp_core::crypto::{ExposeSecret, SecretString, SecretUri, Ss58Codec};
|
||||
use std::str::FromStr;
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `inspect` command
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(
|
||||
name = "inspect",
|
||||
about = "Gets a public key and a SS58 address from the provided Secret URI"
|
||||
)]
|
||||
@@ -44,23 +44,23 @@ pub struct InspectKeyCmd {
|
||||
uri: Option<String>,
|
||||
|
||||
/// Is the given `uri` a hex encoded public key?
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
public: bool,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub keystore_params: KeystoreParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub network_scheme: NetworkSchemeFlag,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub output_scheme: OutputTypeFlag,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub crypto_scheme: CryptoSchemeFlag,
|
||||
|
||||
/// Expect that `--uri` has the given public key/account-id.
|
||||
@@ -72,7 +72,7 @@ pub struct InspectKeyCmd {
|
||||
///
|
||||
/// If there is no derivation in `--uri`, the public key will be checked against the public key
|
||||
/// of `--uri` directly.
|
||||
#[structopt(long, conflicts_with = "public")]
|
||||
#[clap(long, conflicts_with = "public")]
|
||||
pub expect_public: Option<String>,
|
||||
}
|
||||
|
||||
@@ -158,7 +158,6 @@ mod tests {
|
||||
use super::*;
|
||||
use sp_core::crypto::{ByteArray, Pair};
|
||||
use sp_runtime::traits::IdentifyAccount;
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[test]
|
||||
fn inspect() {
|
||||
@@ -166,10 +165,10 @@ mod tests {
|
||||
"remember fiber forum demise paper uniform squirrel feel access exclude casual effort";
|
||||
let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5";
|
||||
|
||||
let inspect = InspectKeyCmd::from_iter(&["inspect-key", words, "--password", "12345"]);
|
||||
let inspect = InspectKeyCmd::parse_from(&["inspect-key", words, "--password", "12345"]);
|
||||
assert!(inspect.run().is_ok());
|
||||
|
||||
let inspect = InspectKeyCmd::from_iter(&["inspect-key", seed]);
|
||||
let inspect = InspectKeyCmd::parse_from(&["inspect-key", seed]);
|
||||
assert!(inspect.run().is_ok());
|
||||
}
|
||||
|
||||
@@ -177,14 +176,14 @@ mod tests {
|
||||
fn inspect_public_key() {
|
||||
let public = "0x12e76e0ae8ce41b6516cce52b3f23a08dcb4cfeed53c6ee8f5eb9f7367341069";
|
||||
|
||||
let inspect = InspectKeyCmd::from_iter(&["inspect-key", "--public", public]);
|
||||
let inspect = InspectKeyCmd::parse_from(&["inspect-key", "--public", public]);
|
||||
assert!(inspect.run().is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inspect_with_expected_public_key() {
|
||||
let check_cmd = |seed, expected_public, success| {
|
||||
let inspect = InspectKeyCmd::from_iter(&[
|
||||
let inspect = InspectKeyCmd::parse_from(&[
|
||||
"inspect-key",
|
||||
"--expect-public",
|
||||
expected_public,
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
//! Implementation of the `inspect-node-key` subcommand
|
||||
|
||||
use crate::{Error, NetworkSchemeFlag};
|
||||
use clap::Parser;
|
||||
use libp2p::identity::{ed25519, PublicKey};
|
||||
use std::{fs, path::PathBuf};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `inspect-node-key` command
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(
|
||||
name = "inspect-node-key",
|
||||
about = "Print the peer ID corresponding to the node key in the given file."
|
||||
)]
|
||||
pub struct InspectNodeKeyCmd {
|
||||
/// Name of file to read the secret key from.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
file: PathBuf,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub network_scheme: NetworkSchemeFlag,
|
||||
}
|
||||
|
||||
@@ -63,11 +63,11 @@ mod tests {
|
||||
fn inspect_node_key() {
|
||||
let path = tempfile::tempdir().unwrap().into_path().join("node-id").into_os_string();
|
||||
let path = path.to_str().unwrap();
|
||||
let cmd = GenerateNodeKeyCmd::from_iter(&["generate-node-key", "--file", path.clone()]);
|
||||
let cmd = GenerateNodeKeyCmd::parse_from(&["generate-node-key", "--file", path.clone()]);
|
||||
|
||||
assert!(cmd.run().is_ok());
|
||||
|
||||
let cmd = InspectNodeKeyCmd::from_iter(&["inspect-node-key", "--file", path]);
|
||||
let cmd = InspectNodeKeyCmd::parse_from(&["inspect-node-key", "--file", path]);
|
||||
assert!(cmd.run().is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,16 +17,14 @@
|
||||
|
||||
//! Key related CLI utilities
|
||||
|
||||
use crate::{Error, SubstrateCli};
|
||||
use structopt::StructOpt;
|
||||
|
||||
use super::{
|
||||
generate::GenerateCmd, generate_node_key::GenerateNodeKeyCmd, insert_key::InsertKeyCmd,
|
||||
inspect_key::InspectKeyCmd, inspect_node_key::InspectNodeKeyCmd,
|
||||
};
|
||||
use crate::{Error, SubstrateCli};
|
||||
|
||||
/// Key utilities for the cli.
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[derive(Debug, clap::Subcommand)]
|
||||
pub enum KeySubcommand {
|
||||
/// Generate a random node libp2p key, save it to file or print it to stdout
|
||||
/// and print its peer ID to stderr.
|
||||
|
||||
@@ -21,27 +21,27 @@ use crate::{
|
||||
params::{DatabaseParams, SharedParams},
|
||||
CliConfiguration,
|
||||
};
|
||||
use clap::Parser;
|
||||
use sc_service::DatabaseSource;
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
fs,
|
||||
io::{self, Write},
|
||||
};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `purge-chain` command used to remove the whole chain.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
pub struct PurgeChainCmd {
|
||||
/// Skip interactive prompt by answering yes automatically.
|
||||
#[structopt(short = "y")]
|
||||
#[clap(short = 'y')]
|
||||
pub yes: bool,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub shared_params: SharedParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub database_params: DatabaseParams,
|
||||
}
|
||||
|
||||
|
||||
@@ -21,25 +21,25 @@ use crate::{
|
||||
params::{GenericNumber, PruningParams, SharedParams},
|
||||
CliConfiguration,
|
||||
};
|
||||
use clap::Parser;
|
||||
use sc_client_api::{Backend, UsageProvider};
|
||||
use sc_service::chain_ops::revert_chain;
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
|
||||
use std::{fmt::Debug, str::FromStr, sync::Arc};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `revert` command used revert the chain to a previous state.
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct RevertCmd {
|
||||
/// Number of blocks to revert.
|
||||
#[structopt(default_value = "256")]
|
||||
#[clap(default_value = "256")]
|
||||
pub num: GenericNumber,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub shared_params: SharedParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub pruning_params: PruningParams,
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ use crate::{
|
||||
},
|
||||
CliConfiguration,
|
||||
};
|
||||
use clap::Parser;
|
||||
use regex::Regex;
|
||||
use sc_service::{
|
||||
config::{BasePath, PrometheusConfig, TransactionPoolOptions},
|
||||
@@ -32,26 +33,25 @@ use sc_service::{
|
||||
};
|
||||
use sc_telemetry::TelemetryEndpoints;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `run` command used to run a node.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
pub struct RunCmd {
|
||||
/// Enable validator mode.
|
||||
///
|
||||
/// The node will be started with the authority role and actively
|
||||
/// participate in any consensus task that it can (e.g. depending on
|
||||
/// availability of local keys).
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub validator: bool,
|
||||
|
||||
/// Disable GRANDPA voter when running in validator mode, otherwise disable the GRANDPA
|
||||
/// observer.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub no_grandpa: bool,
|
||||
|
||||
/// Experimental: Run in light client mode.
|
||||
#[structopt(long = "light")]
|
||||
#[clap(long)]
|
||||
pub light: bool,
|
||||
|
||||
/// Listen to all RPC interfaces.
|
||||
@@ -60,13 +60,13 @@ pub struct RunCmd {
|
||||
/// proxy server to filter out dangerous methods. More details:
|
||||
/// <https://docs.substrate.io/v3/runtime/custom-rpcs/#public-rpcs>.
|
||||
/// Use `--unsafe-rpc-external` to suppress the warning if you understand the risks.
|
||||
#[structopt(long = "rpc-external")]
|
||||
#[clap(long)]
|
||||
pub rpc_external: bool,
|
||||
|
||||
/// Listen to all RPC interfaces.
|
||||
///
|
||||
/// Same as `--rpc-external`.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub unsafe_rpc_external: bool,
|
||||
|
||||
/// RPC methods to expose.
|
||||
@@ -75,11 +75,11 @@ pub struct RunCmd {
|
||||
/// - `Safe`: Exposes only a safe subset of RPC methods, denying unsafe RPC methods.
|
||||
/// - `Auto`: Acts as `Safe` if RPC is served externally, e.g. when `--{rpc,ws}-external` is
|
||||
/// passed, otherwise acts as `Unsafe`.
|
||||
#[structopt(
|
||||
#[clap(
|
||||
long,
|
||||
value_name = "METHOD SET",
|
||||
possible_values = &RpcMethods::variants(),
|
||||
case_insensitive = true,
|
||||
arg_enum,
|
||||
ignore_case = true,
|
||||
default_value = "Auto",
|
||||
verbatim_doc_comment
|
||||
)]
|
||||
@@ -91,44 +91,44 @@ pub struct RunCmd {
|
||||
/// proxy server to filter out dangerous methods. More details:
|
||||
/// <https://docs.substrate.io/v3/runtime/custom-rpcs/#public-rpcs>.
|
||||
/// Use `--unsafe-ws-external` to suppress the warning if you understand the risks.
|
||||
#[structopt(long = "ws-external")]
|
||||
#[clap(long)]
|
||||
pub ws_external: bool,
|
||||
|
||||
/// Listen to all Websocket interfaces.
|
||||
///
|
||||
/// Same as `--ws-external` but doesn't warn you about it.
|
||||
#[structopt(long = "unsafe-ws-external")]
|
||||
#[clap(long)]
|
||||
pub unsafe_ws_external: bool,
|
||||
|
||||
/// Set the the maximum RPC payload size for both requests and responses (both http and ws), in
|
||||
/// megabytes. Default is 15MiB.
|
||||
#[structopt(long = "rpc-max-payload")]
|
||||
#[clap(long)]
|
||||
pub rpc_max_payload: Option<usize>,
|
||||
|
||||
/// Expose Prometheus exporter on all interfaces.
|
||||
///
|
||||
/// Default is local.
|
||||
#[structopt(long = "prometheus-external")]
|
||||
#[clap(long)]
|
||||
pub prometheus_external: bool,
|
||||
|
||||
/// Specify IPC RPC server path
|
||||
#[structopt(long = "ipc-path", value_name = "PATH")]
|
||||
#[clap(long, value_name = "PATH")]
|
||||
pub ipc_path: Option<String>,
|
||||
|
||||
/// Specify HTTP RPC server TCP port.
|
||||
#[structopt(long = "rpc-port", value_name = "PORT")]
|
||||
#[clap(long, value_name = "PORT")]
|
||||
pub rpc_port: Option<u16>,
|
||||
|
||||
/// Specify WebSockets RPC server TCP port.
|
||||
#[structopt(long = "ws-port", value_name = "PORT")]
|
||||
#[clap(long, value_name = "PORT")]
|
||||
pub ws_port: Option<u16>,
|
||||
|
||||
/// Maximum number of WS RPC server connections.
|
||||
#[structopt(long = "ws-max-connections", value_name = "COUNT")]
|
||||
#[clap(long, value_name = "COUNT")]
|
||||
pub ws_max_connections: Option<usize>,
|
||||
|
||||
/// Set the the maximum WebSocket output buffer size in MiB. Default is 16.
|
||||
#[structopt(long = "ws-max-out-buffer-capacity")]
|
||||
#[clap(long)]
|
||||
pub ws_max_out_buffer_capacity: Option<usize>,
|
||||
|
||||
/// Specify browser Origins allowed to access the HTTP & WS RPC servers.
|
||||
@@ -137,29 +137,29 @@ pub struct RunCmd {
|
||||
/// value). Value of `all` will disable origin validation. Default is to
|
||||
/// allow localhost and <https://polkadot.js.org> origins. When running in
|
||||
/// --dev mode the default is to allow all origins.
|
||||
#[structopt(long = "rpc-cors", value_name = "ORIGINS", parse(try_from_str = parse_cors))]
|
||||
#[clap(long, value_name = "ORIGINS", parse(from_str = parse_cors))]
|
||||
pub rpc_cors: Option<Cors>,
|
||||
|
||||
/// Specify Prometheus exporter TCP Port.
|
||||
#[structopt(long = "prometheus-port", value_name = "PORT")]
|
||||
#[clap(long, value_name = "PORT")]
|
||||
pub prometheus_port: Option<u16>,
|
||||
|
||||
/// Do not expose a Prometheus exporter endpoint.
|
||||
///
|
||||
/// Prometheus metric endpoint is enabled by default.
|
||||
#[structopt(long = "no-prometheus")]
|
||||
#[clap(long)]
|
||||
pub no_prometheus: bool,
|
||||
|
||||
/// The human-readable name for this node.
|
||||
///
|
||||
/// The node name will be reported to the telemetry server, if enabled.
|
||||
#[structopt(long = "name", value_name = "NAME")]
|
||||
#[clap(long, value_name = "NAME")]
|
||||
pub name: Option<String>,
|
||||
|
||||
/// Disable connecting to the Substrate telemetry server.
|
||||
///
|
||||
/// Telemetry is on by default on global chains.
|
||||
#[structopt(long = "no-telemetry")]
|
||||
#[clap(long)]
|
||||
pub no_telemetry: bool,
|
||||
|
||||
/// The URL of the telemetry server to connect to.
|
||||
@@ -168,78 +168,78 @@ pub struct RunCmd {
|
||||
/// telemetry endpoints. Verbosity levels range from 0-9, with 0 denoting
|
||||
/// the least verbosity.
|
||||
/// Expected format is 'URL VERBOSITY', e.g. `--telemetry-url 'wss://foo/bar 0'`.
|
||||
#[structopt(long = "telemetry-url", value_name = "URL VERBOSITY", parse(try_from_str = parse_telemetry_endpoints))]
|
||||
#[clap(long = "telemetry-url", value_name = "URL VERBOSITY", parse(try_from_str = parse_telemetry_endpoints))]
|
||||
pub telemetry_endpoints: Vec<(String, u8)>,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub offchain_worker_params: OffchainWorkerParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub shared_params: SharedParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub import_params: ImportParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub network_params: NetworkParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub pool_config: TransactionPoolParams,
|
||||
|
||||
/// Shortcut for `--name Alice --validator` with session keys for `Alice` added to keystore.
|
||||
#[structopt(long, conflicts_with_all = &["bob", "charlie", "dave", "eve", "ferdie", "one", "two"])]
|
||||
#[clap(long, conflicts_with_all = &["bob", "charlie", "dave", "eve", "ferdie", "one", "two"])]
|
||||
pub alice: bool,
|
||||
|
||||
/// Shortcut for `--name Bob --validator` with session keys for `Bob` added to keystore.
|
||||
#[structopt(long, conflicts_with_all = &["alice", "charlie", "dave", "eve", "ferdie", "one", "two"])]
|
||||
#[clap(long, conflicts_with_all = &["alice", "charlie", "dave", "eve", "ferdie", "one", "two"])]
|
||||
pub bob: bool,
|
||||
|
||||
/// Shortcut for `--name Charlie --validator` with session keys for `Charlie` added to
|
||||
/// keystore.
|
||||
#[structopt(long, conflicts_with_all = &["alice", "bob", "dave", "eve", "ferdie", "one", "two"])]
|
||||
#[clap(long, conflicts_with_all = &["alice", "bob", "dave", "eve", "ferdie", "one", "two"])]
|
||||
pub charlie: bool,
|
||||
|
||||
/// Shortcut for `--name Dave --validator` with session keys for `Dave` added to keystore.
|
||||
#[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "eve", "ferdie", "one", "two"])]
|
||||
#[clap(long, conflicts_with_all = &["alice", "bob", "charlie", "eve", "ferdie", "one", "two"])]
|
||||
pub dave: bool,
|
||||
|
||||
/// Shortcut for `--name Eve --validator` with session keys for `Eve` added to keystore.
|
||||
#[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "ferdie", "one", "two"])]
|
||||
#[clap(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "ferdie", "one", "two"])]
|
||||
pub eve: bool,
|
||||
|
||||
/// Shortcut for `--name Ferdie --validator` with session keys for `Ferdie` added to keystore.
|
||||
#[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "one", "two"])]
|
||||
#[clap(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "one", "two"])]
|
||||
pub ferdie: bool,
|
||||
|
||||
/// Shortcut for `--name One --validator` with session keys for `One` added to keystore.
|
||||
#[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "ferdie", "two"])]
|
||||
#[clap(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "ferdie", "two"])]
|
||||
pub one: bool,
|
||||
|
||||
/// Shortcut for `--name Two --validator` with session keys for `Two` added to keystore.
|
||||
#[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "ferdie", "one"])]
|
||||
#[clap(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "ferdie", "one"])]
|
||||
pub two: bool,
|
||||
|
||||
/// Enable authoring even when offline.
|
||||
#[structopt(long = "force-authoring")]
|
||||
#[clap(long)]
|
||||
pub force_authoring: bool,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub keystore_params: KeystoreParams,
|
||||
|
||||
/// The size of the instances cache for each runtime.
|
||||
///
|
||||
/// The default value is 8 and the values higher than 256 are ignored.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub max_runtime_instances: Option<usize>,
|
||||
|
||||
/// Maximum number of different runtimes that can be cached.
|
||||
#[structopt(long, default_value = "2")]
|
||||
#[clap(long, default_value = "2")]
|
||||
pub runtime_cache_size: u8,
|
||||
|
||||
/// Run a temporary node.
|
||||
@@ -251,7 +251,7 @@ pub struct RunCmd {
|
||||
/// which includes: database, node key and keystore.
|
||||
///
|
||||
/// When `--dev` is given and no explicit `--base-path`, this option is implied.
|
||||
#[structopt(long, conflicts_with = "base-path")]
|
||||
#[clap(long, conflicts_with = "base-path")]
|
||||
pub tmp: bool,
|
||||
}
|
||||
|
||||
@@ -562,8 +562,7 @@ fn parse_telemetry_endpoints(s: &str) -> std::result::Result<(String, u8), Telem
|
||||
|
||||
/// CORS setting
|
||||
///
|
||||
/// The type is introduced to overcome `Option<Option<T>>`
|
||||
/// handling of `structopt`.
|
||||
/// The type is introduced to overcome `Option<Option<T>>` handling of `clap`.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Cors {
|
||||
/// All hosts allowed.
|
||||
@@ -582,7 +581,7 @@ impl From<Cors> for Option<Vec<String>> {
|
||||
}
|
||||
|
||||
/// Parse cors origins.
|
||||
fn parse_cors(s: &str) -> std::result::Result<Cors, Box<dyn std::error::Error>> {
|
||||
fn parse_cors(s: &str) -> Cors {
|
||||
let mut is_all = false;
|
||||
let mut origins = Vec::new();
|
||||
for part in s.split(',') {
|
||||
@@ -595,7 +594,11 @@ fn parse_cors(s: &str) -> std::result::Result<Cors, Box<dyn std::error::Error>>
|
||||
}
|
||||
}
|
||||
|
||||
Ok(if is_all { Cors::All } else { Cors::List(origins) })
|
||||
if is_all {
|
||||
Cors::All
|
||||
} else {
|
||||
Cors::List(origins)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -18,34 +18,34 @@
|
||||
|
||||
//! Implementation of the `sign` subcommand
|
||||
use crate::{error, utils, with_crypto_scheme, CryptoSchemeFlag, KeystoreParams};
|
||||
use clap::Parser;
|
||||
use sp_core::crypto::SecretString;
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `sign` command
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[structopt(name = "sign", about = "Sign a message, with a given (secret) key")]
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
#[clap(name = "sign", about = "Sign a message, with a given (secret) key")]
|
||||
pub struct SignCmd {
|
||||
/// The secret key URI.
|
||||
/// If the value is a file, the file content is used as URI.
|
||||
/// If not given, you will be prompted for the URI.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
suri: Option<String>,
|
||||
|
||||
/// Message to sign, if not provided you will be prompted to
|
||||
/// pass the message via STDIN
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
message: Option<String>,
|
||||
|
||||
/// The message on STDIN is hex-encoded data
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
hex: bool,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub keystore_params: KeystoreParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub crypto_scheme: CryptoSchemeFlag,
|
||||
}
|
||||
|
||||
@@ -75,14 +75,13 @@ fn sign<P: sp_core::Pair>(
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::SignCmd;
|
||||
use structopt::StructOpt;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn sign() {
|
||||
let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5";
|
||||
|
||||
let sign = SignCmd::from_iter(&[
|
||||
let sign = SignCmd::parse_from(&[
|
||||
"sign",
|
||||
"--suri",
|
||||
seed,
|
||||
|
||||
@@ -21,30 +21,30 @@
|
||||
use crate::{
|
||||
error, utils, with_crypto_scheme, CryptoSchemeFlag, NetworkSchemeFlag, OutputTypeFlag,
|
||||
};
|
||||
use clap::Parser;
|
||||
use rand::{rngs::OsRng, RngCore};
|
||||
use sp_core::crypto::{unwrap_or_default_ss58_version, Ss58AddressFormat, Ss58Codec};
|
||||
use sp_runtime::traits::IdentifyAccount;
|
||||
use structopt::StructOpt;
|
||||
use utils::print_from_uri;
|
||||
|
||||
/// The `vanity` command
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[structopt(name = "vanity", about = "Generate a seed that provides a vanity address")]
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
#[clap(name = "vanity", about = "Generate a seed that provides a vanity address")]
|
||||
pub struct VanityCmd {
|
||||
/// Desired pattern
|
||||
#[structopt(long, parse(try_from_str = assert_non_empty_string))]
|
||||
#[clap(long, parse(try_from_str = assert_non_empty_string))]
|
||||
pattern: String,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
network_scheme: NetworkSchemeFlag,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
output_scheme: OutputTypeFlag,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
crypto_scheme: CryptoSchemeFlag,
|
||||
}
|
||||
|
||||
@@ -166,13 +166,12 @@ mod tests {
|
||||
crypto::{default_ss58_version, Ss58AddressFormatRegistry, Ss58Codec},
|
||||
sr25519, Pair,
|
||||
};
|
||||
use structopt::StructOpt;
|
||||
#[cfg(feature = "bench")]
|
||||
use test::Bencher;
|
||||
|
||||
#[test]
|
||||
fn vanity() {
|
||||
let vanity = VanityCmd::from_iter(&["vanity", "--pattern", "j"]);
|
||||
let vanity = VanityCmd::parse_from(&["vanity", "--pattern", "j"]);
|
||||
assert!(vanity.run().is_ok());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
//! implementation of the `verify` subcommand
|
||||
|
||||
use crate::{error, utils, with_crypto_scheme, CryptoSchemeFlag};
|
||||
use clap::Parser;
|
||||
use sp_core::crypto::{ByteArray, Ss58Codec};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `verify` command
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[structopt(
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
#[clap(
|
||||
name = "verify",
|
||||
about = "Verify a signature for a message, provided on STDIN, with a given (public or secret) key"
|
||||
)]
|
||||
@@ -39,15 +39,15 @@ pub struct VerifyCmd {
|
||||
|
||||
/// Message to verify, if not provided you will be prompted to
|
||||
/// pass the message via STDIN
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
message: Option<String>,
|
||||
|
||||
/// The message on STDIN is hex-encoded data
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
hex: bool,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub crypto_scheme: CryptoSchemeFlag,
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ pub enum Error {
|
||||
Io(#[from] std::io::Error),
|
||||
|
||||
#[error(transparent)]
|
||||
Cli(#[from] structopt::clap::Error),
|
||||
Cli(#[from] clap::Error),
|
||||
|
||||
#[error(transparent)]
|
||||
Service(#[from] sc_service::Error),
|
||||
|
||||
@@ -30,6 +30,8 @@ mod params;
|
||||
mod runner;
|
||||
|
||||
pub use arg_enums::*;
|
||||
pub use clap;
|
||||
use clap::{AppSettings, FromArgMatches, IntoApp, Parser};
|
||||
pub use commands::*;
|
||||
pub use config::*;
|
||||
pub use error::*;
|
||||
@@ -39,12 +41,6 @@ use sc_service::Configuration;
|
||||
pub use sc_service::{ChainSpec, Role};
|
||||
pub use sc_tracing::logging::LoggerBuilder;
|
||||
pub use sp_version::RuntimeVersion;
|
||||
use std::io::Write;
|
||||
pub use structopt;
|
||||
use structopt::{
|
||||
clap::{self, AppSettings},
|
||||
StructOpt,
|
||||
};
|
||||
|
||||
/// Substrate client CLI
|
||||
///
|
||||
@@ -103,7 +99,7 @@ pub trait SubstrateCli: Sized {
|
||||
/// error message and quit the program in case of failure.
|
||||
fn from_args() -> Self
|
||||
where
|
||||
Self: StructOpt + Sized,
|
||||
Self: Parser + Sized,
|
||||
{
|
||||
<Self as SubstrateCli>::from_iter(&mut std::env::args_os())
|
||||
}
|
||||
@@ -120,11 +116,11 @@ pub trait SubstrateCli: Sized {
|
||||
/// Print the error message and quit the program in case of failure.
|
||||
fn from_iter<I>(iter: I) -> Self
|
||||
where
|
||||
Self: StructOpt + Sized,
|
||||
Self: Parser + Sized,
|
||||
I: IntoIterator,
|
||||
I::Item: Into<std::ffi::OsString> + Clone,
|
||||
{
|
||||
let app = <Self as StructOpt>::clap();
|
||||
let app = <Self as IntoApp>::into_app();
|
||||
|
||||
let mut full_version = Self::impl_version();
|
||||
full_version.push_str("\n");
|
||||
@@ -137,34 +133,15 @@ pub trait SubstrateCli: Sized {
|
||||
.author(author.as_str())
|
||||
.about(about.as_str())
|
||||
.version(full_version.as_str())
|
||||
.settings(&[
|
||||
AppSettings::GlobalVersion,
|
||||
AppSettings::ArgsNegateSubcommands,
|
||||
AppSettings::SubcommandsNegateReqs,
|
||||
AppSettings::ColoredHelp,
|
||||
]);
|
||||
.setting(
|
||||
AppSettings::PropagateVersion |
|
||||
AppSettings::ArgsNegateSubcommands |
|
||||
AppSettings::SubcommandsNegateReqs,
|
||||
);
|
||||
|
||||
let matches = match app.get_matches_from_safe(iter) {
|
||||
Ok(matches) => matches,
|
||||
Err(mut e) => {
|
||||
// To support pipes, we can not use `writeln!` as any error
|
||||
// results in a "broken pipe" error.
|
||||
//
|
||||
// Instead we write directly to `stdout` and ignore any error
|
||||
// as we exit afterwards anyway.
|
||||
e.message.extend("\n".chars());
|
||||
let matches = app.try_get_matches_from(iter).unwrap_or_else(|e| e.exit());
|
||||
|
||||
if e.use_stderr() {
|
||||
let _ = std::io::stderr().write_all(e.message.as_bytes());
|
||||
std::process::exit(1);
|
||||
} else {
|
||||
let _ = std::io::stdout().write_all(e.message.as_bytes());
|
||||
std::process::exit(0);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
<Self as StructOpt>::from_clap(&matches)
|
||||
<Self as FromArgMatches>::from_arg_matches(&matches).unwrap_or_else(|e| e.exit())
|
||||
}
|
||||
|
||||
/// Helper function used to parse the command line arguments. This is the equivalent of
|
||||
@@ -180,15 +157,15 @@ pub trait SubstrateCli: Sized {
|
||||
///
|
||||
/// **NOTE:** This method WILL NOT exit when `--help` or `--version` (or short versions) are
|
||||
/// used. It will return a [`clap::Error`], where the [`clap::Error::kind`] is a
|
||||
/// [`clap::ErrorKind::HelpDisplayed`] or [`clap::ErrorKind::VersionDisplayed`] respectively.
|
||||
/// [`clap::ErrorKind::DisplayHelp`] or [`clap::ErrorKind::DisplayVersion`] respectively.
|
||||
/// You must call [`clap::Error::exit`] or perform a [`std::process::exit`].
|
||||
fn try_from_iter<I>(iter: I) -> clap::Result<Self>
|
||||
where
|
||||
Self: StructOpt + Sized,
|
||||
Self: Parser + Sized,
|
||||
I: IntoIterator,
|
||||
I::Item: Into<std::ffi::OsString> + Clone,
|
||||
{
|
||||
let app = <Self as StructOpt>::clap();
|
||||
let app = <Self as IntoApp>::into_app();
|
||||
|
||||
let mut full_version = Self::impl_version();
|
||||
full_version.push_str("\n");
|
||||
@@ -202,9 +179,9 @@ pub trait SubstrateCli: Sized {
|
||||
.about(about.as_str())
|
||||
.version(full_version.as_str());
|
||||
|
||||
let matches = app.get_matches_from_safe(iter)?;
|
||||
let matches = app.try_get_matches_from(iter)?;
|
||||
|
||||
Ok(<Self as StructOpt>::from_clap(&matches))
|
||||
<Self as FromArgMatches>::from_arg_matches(&matches)
|
||||
}
|
||||
|
||||
/// Returns the client ID: `{impl_name}/v{impl_version}`
|
||||
|
||||
@@ -17,24 +17,24 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::arg_enums::Database;
|
||||
use clap::Args;
|
||||
use sc_service::TransactionStorageMode;
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// Parameters for block import.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct DatabaseParams {
|
||||
/// Select database backend to use.
|
||||
#[structopt(
|
||||
#[clap(
|
||||
long,
|
||||
alias = "db",
|
||||
value_name = "DB",
|
||||
case_insensitive = true,
|
||||
possible_values = &Database::variants(),
|
||||
ignore_case = true,
|
||||
possible_values = Database::variants(),
|
||||
)]
|
||||
pub database: Option<Database>,
|
||||
|
||||
/// Limit the memory the database cache can use.
|
||||
#[structopt(long = "db-cache", value_name = "MiB")]
|
||||
#[clap(long = "db-cache", value_name = "MiB")]
|
||||
pub database_cache_size: Option<usize>,
|
||||
|
||||
/// Enable storage chain mode
|
||||
@@ -43,7 +43,7 @@ pub struct DatabaseParams {
|
||||
/// If this is enabled, each transaction is stored separately in the
|
||||
/// transaction database column and is only referenced by hash
|
||||
/// in the block body column.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub storage_chain: bool,
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ use crate::{
|
||||
},
|
||||
params::{DatabaseParams, PruningParams},
|
||||
};
|
||||
use clap::Args;
|
||||
use sc_client_api::execution_extensions::ExecutionStrategies;
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[cfg(feature = "wasmtime")]
|
||||
const WASM_METHOD_DEFAULT: &str = "Compiled";
|
||||
@@ -35,14 +35,14 @@ const WASM_METHOD_DEFAULT: &str = "Compiled";
|
||||
const WASM_METHOD_DEFAULT: &str = "interpreted-i-know-what-i-do";
|
||||
|
||||
/// Parameters for block import.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct ImportParams {
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub pruning_params: PruningParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub database_params: DatabaseParams,
|
||||
|
||||
/// Force start with unsafe pruning settings.
|
||||
@@ -50,15 +50,15 @@ pub struct ImportParams {
|
||||
/// When running as a validator it is highly recommended to disable state
|
||||
/// pruning (i.e. 'archive') which is the default. The node will refuse to
|
||||
/// start as a validator if pruning is enabled unless this option is set.
|
||||
#[structopt(long = "unsafe-pruning")]
|
||||
#[clap(long)]
|
||||
pub unsafe_pruning: bool,
|
||||
|
||||
/// Method for executing Wasm runtime code.
|
||||
#[structopt(
|
||||
#[clap(
|
||||
long = "wasm-execution",
|
||||
value_name = "METHOD",
|
||||
possible_values = &WasmExecutionMethod::variants(),
|
||||
case_insensitive = true,
|
||||
possible_values = WasmExecutionMethod::variants(),
|
||||
ignore_case = true,
|
||||
default_value = WASM_METHOD_DEFAULT
|
||||
)]
|
||||
pub wasm_method: WasmExecutionMethod,
|
||||
@@ -66,15 +66,15 @@ pub struct ImportParams {
|
||||
/// Specify the path where local WASM runtimes are stored.
|
||||
///
|
||||
/// These runtimes will override on-chain runtimes when the version matches.
|
||||
#[structopt(long, value_name = "PATH", parse(from_os_str))]
|
||||
#[clap(long, value_name = "PATH", parse(from_os_str))]
|
||||
pub wasm_runtime_overrides: Option<PathBuf>,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub execution_strategies: ExecutionStrategiesParams,
|
||||
|
||||
/// Specify the state cache size.
|
||||
#[structopt(long = "state-cache-size", value_name = "Bytes", default_value = "67108864")]
|
||||
#[clap(long, value_name = "Bytes", default_value = "67108864")]
|
||||
pub state_cache_size: usize,
|
||||
}
|
||||
|
||||
@@ -127,62 +127,37 @@ impl ImportParams {
|
||||
}
|
||||
|
||||
/// Execution strategies parameters.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct ExecutionStrategiesParams {
|
||||
/// The means of execution used when calling into the runtime for importing blocks as
|
||||
/// part of an initial sync.
|
||||
#[structopt(
|
||||
long = "execution-syncing",
|
||||
value_name = "STRATEGY",
|
||||
possible_values = &ExecutionStrategy::variants(),
|
||||
case_insensitive = true,
|
||||
)]
|
||||
#[clap(long, value_name = "STRATEGY", arg_enum, ignore_case = true)]
|
||||
pub execution_syncing: Option<ExecutionStrategy>,
|
||||
|
||||
/// The means of execution used when calling into the runtime for general block import
|
||||
/// (including locally authored blocks).
|
||||
#[structopt(
|
||||
long = "execution-import-block",
|
||||
value_name = "STRATEGY",
|
||||
possible_values = &ExecutionStrategy::variants(),
|
||||
case_insensitive = true,
|
||||
)]
|
||||
#[clap(long, value_name = "STRATEGY", arg_enum, ignore_case = true)]
|
||||
pub execution_import_block: Option<ExecutionStrategy>,
|
||||
|
||||
/// The means of execution used when calling into the runtime while constructing blocks.
|
||||
#[structopt(
|
||||
long = "execution-block-construction",
|
||||
value_name = "STRATEGY",
|
||||
possible_values = &ExecutionStrategy::variants(),
|
||||
case_insensitive = true,
|
||||
)]
|
||||
#[clap(long, value_name = "STRATEGY", arg_enum, ignore_case = true)]
|
||||
pub execution_block_construction: Option<ExecutionStrategy>,
|
||||
|
||||
/// The means of execution used when calling into the runtime while using an off-chain worker.
|
||||
#[structopt(
|
||||
long = "execution-offchain-worker",
|
||||
value_name = "STRATEGY",
|
||||
possible_values = &ExecutionStrategy::variants(),
|
||||
case_insensitive = true,
|
||||
)]
|
||||
#[clap(long, value_name = "STRATEGY", arg_enum, ignore_case = true)]
|
||||
pub execution_offchain_worker: Option<ExecutionStrategy>,
|
||||
|
||||
/// The means of execution used when calling into the runtime while not syncing, importing or
|
||||
/// constructing blocks.
|
||||
#[structopt(
|
||||
long = "execution-other",
|
||||
value_name = "STRATEGY",
|
||||
possible_values = &ExecutionStrategy::variants(),
|
||||
case_insensitive = true,
|
||||
)]
|
||||
#[clap(long, value_name = "STRATEGY", arg_enum, ignore_case = true)]
|
||||
pub execution_other: Option<ExecutionStrategy>,
|
||||
|
||||
/// The execution strategy that should be used by all execution contexts.
|
||||
#[structopt(
|
||||
long = "execution",
|
||||
#[clap(
|
||||
long,
|
||||
value_name = "STRATEGY",
|
||||
possible_values = &ExecutionStrategy::variants(),
|
||||
case_insensitive = true,
|
||||
arg_enum,
|
||||
ignore_case = true,
|
||||
conflicts_with_all = &[
|
||||
"execution-other",
|
||||
"execution-offchain-worker",
|
||||
|
||||
@@ -17,50 +17,47 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{error, error::Result};
|
||||
use clap::Args;
|
||||
use sc_service::config::KeystoreConfig;
|
||||
use sp_core::crypto::SecretString;
|
||||
use std::{
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// default sub directory for the key store
|
||||
const DEFAULT_KEYSTORE_CONFIG_PATH: &'static str = "keystore";
|
||||
|
||||
/// Parameters of the keystore
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct KeystoreParams {
|
||||
/// Specify custom URIs to connect to for keystore-services
|
||||
#[structopt(long = "keystore-uri")]
|
||||
#[clap(long)]
|
||||
pub keystore_uri: Option<String>,
|
||||
|
||||
/// Specify custom keystore path.
|
||||
#[structopt(long = "keystore-path", value_name = "PATH", parse(from_os_str))]
|
||||
#[clap(long, value_name = "PATH", parse(from_os_str))]
|
||||
pub keystore_path: Option<PathBuf>,
|
||||
|
||||
/// Use interactive shell for entering the password used by the keystore.
|
||||
#[structopt(
|
||||
long = "password-interactive",
|
||||
conflicts_with_all = &[ "password", "password-filename" ]
|
||||
)]
|
||||
#[clap(long, conflicts_with_all = &["password", "password-filename"])]
|
||||
pub password_interactive: bool,
|
||||
|
||||
/// Password used by the keystore. This allows appending an extra user-defined secret to the
|
||||
/// seed.
|
||||
#[structopt(
|
||||
long = "password",
|
||||
#[clap(
|
||||
long,
|
||||
parse(try_from_str = secret_string_from_str),
|
||||
conflicts_with_all = &[ "password-interactive", "password-filename" ]
|
||||
conflicts_with_all = &["password-interactive", "password-filename"]
|
||||
)]
|
||||
pub password: Option<SecretString>,
|
||||
|
||||
/// File that contains the password used by the keystore.
|
||||
#[structopt(
|
||||
long = "password-filename",
|
||||
#[clap(
|
||||
long,
|
||||
value_name = "PATH",
|
||||
parse(from_os_str),
|
||||
conflicts_with_all = &[ "password-interactive", "password" ]
|
||||
conflicts_with_all = &["password-interactive", "password"]
|
||||
)]
|
||||
pub password_filename: Option<PathBuf>,
|
||||
}
|
||||
|
||||
@@ -26,13 +26,13 @@ mod shared_params;
|
||||
mod transaction_pool_params;
|
||||
|
||||
use crate::arg_enums::{CryptoScheme, OutputType};
|
||||
use clap::Args;
|
||||
use sp_core::crypto::Ss58AddressFormat;
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{Block as BlockT, NumberFor},
|
||||
};
|
||||
use std::{convert::TryFrom, fmt::Debug, str::FromStr};
|
||||
use structopt::StructOpt;
|
||||
|
||||
pub use crate::params::{
|
||||
database_params::*, import_params::*, keystore_params::*, network_params::*,
|
||||
@@ -115,44 +115,32 @@ impl BlockNumberOrHash {
|
||||
}
|
||||
|
||||
/// Optional flag for specifying crypto algorithm
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct CryptoSchemeFlag {
|
||||
/// cryptography scheme
|
||||
#[structopt(
|
||||
long,
|
||||
value_name = "SCHEME",
|
||||
possible_values = &CryptoScheme::variants(),
|
||||
case_insensitive = true,
|
||||
default_value = "Sr25519"
|
||||
)]
|
||||
#[clap(long, value_name = "SCHEME", arg_enum, ignore_case = true, default_value = "Sr25519")]
|
||||
pub scheme: CryptoScheme,
|
||||
}
|
||||
|
||||
/// Optional flag for specifying output type
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct OutputTypeFlag {
|
||||
/// output format
|
||||
#[structopt(
|
||||
long,
|
||||
value_name = "FORMAT",
|
||||
possible_values = &OutputType::variants(),
|
||||
case_insensitive = true,
|
||||
default_value = "Text"
|
||||
)]
|
||||
#[clap(long, value_name = "FORMAT", arg_enum, ignore_case = true, default_value = "Text")]
|
||||
pub output_type: OutputType,
|
||||
}
|
||||
|
||||
/// Optional flag for specifying network scheme
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct NetworkSchemeFlag {
|
||||
/// network address format
|
||||
#[structopt(
|
||||
#[clap(
|
||||
short = 'n',
|
||||
long,
|
||||
value_name = "NETWORK",
|
||||
short = "n",
|
||||
possible_values = &Ss58AddressFormat::all_names()[..],
|
||||
ignore_case = true,
|
||||
parse(try_from_str = Ss58AddressFormat::try_from),
|
||||
case_insensitive = true,
|
||||
)]
|
||||
pub network: Option<Ss58AddressFormat>,
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{arg_enums::SyncMode, params::node_key_params::NodeKeyParams};
|
||||
use clap::Args;
|
||||
use sc_network::{
|
||||
config::{
|
||||
NetworkConfiguration, NodeKeyConfig, NonReservedPeerMode, SetConfig, TransportConfig,
|
||||
@@ -28,17 +29,16 @@ use sc_service::{
|
||||
ChainSpec, ChainType,
|
||||
};
|
||||
use std::{borrow::Cow, path::PathBuf};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// Parameters used to create the network configuration.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct NetworkParams {
|
||||
/// Specify a list of bootnodes.
|
||||
#[structopt(long = "bootnodes", value_name = "ADDR")]
|
||||
#[clap(long, value_name = "ADDR")]
|
||||
pub bootnodes: Vec<MultiaddrWithPeerId>,
|
||||
|
||||
/// Specify a list of reserved node addresses.
|
||||
#[structopt(long = "reserved-nodes", value_name = "ADDR")]
|
||||
#[clap(long, value_name = "ADDR")]
|
||||
pub reserved_nodes: Vec<MultiaddrWithPeerId>,
|
||||
|
||||
/// Whether to only synchronize the chain with reserved nodes.
|
||||
@@ -49,12 +49,12 @@ pub struct NetworkParams {
|
||||
/// In particular, if you are a validator your node might still connect to other
|
||||
/// validator nodes and collator nodes regardless of whether they are defined as
|
||||
/// reserved nodes.
|
||||
#[structopt(long = "reserved-only")]
|
||||
#[clap(long)]
|
||||
pub reserved_only: bool,
|
||||
|
||||
/// The public address that other nodes will use to connect to it.
|
||||
/// This can be used if there's a proxy in front of this node.
|
||||
#[structopt(long, value_name = "PUBLIC_ADDR")]
|
||||
#[clap(long, value_name = "PUBLIC_ADDR")]
|
||||
pub public_addr: Vec<Multiaddr>,
|
||||
|
||||
/// Listen on this multiaddress.
|
||||
@@ -62,60 +62,60 @@ pub struct NetworkParams {
|
||||
/// By default:
|
||||
/// If `--validator` is passed: `/ip4/0.0.0.0/tcp/<port>` and `/ip6/[::]/tcp/<port>`.
|
||||
/// Otherwise: `/ip4/0.0.0.0/tcp/<port>/ws` and `/ip6/[::]/tcp/<port>/ws`.
|
||||
#[structopt(long = "listen-addr", value_name = "LISTEN_ADDR")]
|
||||
#[clap(long, value_name = "LISTEN_ADDR")]
|
||||
pub listen_addr: Vec<Multiaddr>,
|
||||
|
||||
/// Specify p2p protocol TCP port.
|
||||
#[structopt(long = "port", value_name = "PORT", conflicts_with_all = &[ "listen-addr" ])]
|
||||
#[clap(long, value_name = "PORT", conflicts_with_all = &[ "listen-addr" ])]
|
||||
pub port: Option<u16>,
|
||||
|
||||
/// Always forbid connecting to private IPv4 addresses (as specified in
|
||||
/// [RFC1918](https://tools.ietf.org/html/rfc1918)), unless the address was passed with
|
||||
/// `--reserved-nodes` or `--bootnodes`. Enabled by default for chains marked as "live" in
|
||||
/// their chain specifications.
|
||||
#[structopt(long = "no-private-ipv4", conflicts_with_all = &["allow-private-ipv4"])]
|
||||
#[clap(long, conflicts_with_all = &["allow-private-ipv4"])]
|
||||
pub no_private_ipv4: bool,
|
||||
|
||||
/// Always accept connecting to private IPv4 addresses (as specified in
|
||||
/// [RFC1918](https://tools.ietf.org/html/rfc1918)). Enabled by default for chains marked as
|
||||
/// "local" in their chain specifications, or when `--dev` is passed.
|
||||
#[structopt(long = "allow-private-ipv4", conflicts_with_all = &["no-private-ipv4"])]
|
||||
#[clap(long, conflicts_with_all = &["no-private-ipv4"])]
|
||||
pub allow_private_ipv4: bool,
|
||||
|
||||
/// Specify the number of outgoing connections we're trying to maintain.
|
||||
#[structopt(long = "out-peers", value_name = "COUNT", default_value = "25")]
|
||||
#[clap(long, value_name = "COUNT", default_value = "25")]
|
||||
pub out_peers: u32,
|
||||
|
||||
/// Maximum number of inbound full nodes peers.
|
||||
#[structopt(long = "in-peers", value_name = "COUNT", default_value = "25")]
|
||||
#[clap(long, value_name = "COUNT", default_value = "25")]
|
||||
pub in_peers: u32,
|
||||
/// Maximum number of inbound light nodes peers.
|
||||
#[structopt(long = "in-peers-light", value_name = "COUNT", default_value = "100")]
|
||||
#[clap(long, value_name = "COUNT", default_value = "100")]
|
||||
pub in_peers_light: u32,
|
||||
|
||||
/// Disable mDNS discovery.
|
||||
///
|
||||
/// By default, the network will use mDNS to discover other nodes on the
|
||||
/// local network. This disables it. Automatically implied when using --dev.
|
||||
#[structopt(long = "no-mdns")]
|
||||
#[clap(long)]
|
||||
pub no_mdns: bool,
|
||||
|
||||
/// Maximum number of peers from which to ask for the same blocks in parallel.
|
||||
///
|
||||
/// This allows downloading announced blocks from multiple peers. Decrease to save
|
||||
/// traffic and risk increased latency.
|
||||
#[structopt(long = "max-parallel-downloads", value_name = "COUNT", default_value = "5")]
|
||||
#[clap(long, value_name = "COUNT", default_value = "5")]
|
||||
pub max_parallel_downloads: u32,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
#[clap(flatten)]
|
||||
pub node_key_params: NodeKeyParams,
|
||||
|
||||
/// Enable peer discovery on local networks.
|
||||
///
|
||||
/// By default this option is `true` for `--dev` or when the chain type is
|
||||
/// `Local`/`Development` and false otherwise.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub discover_local: bool,
|
||||
|
||||
/// Require iterative Kademlia DHT queries to use disjoint paths for increased resiliency in
|
||||
@@ -123,11 +123,11 @@ pub struct NetworkParams {
|
||||
///
|
||||
/// See the S/Kademlia paper for more information on the high level design as well as its
|
||||
/// security improvements.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub kademlia_disjoint_query_paths: bool,
|
||||
|
||||
/// Join the IPFS network and serve transactions over bitswap protocol.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub ipfs_server: bool,
|
||||
|
||||
/// Blockchain syncing mode.
|
||||
@@ -137,7 +137,7 @@ pub struct NetworkParams {
|
||||
/// - `Fast`: Download blocks and the latest state only.
|
||||
///
|
||||
/// - `FastUnsafe`: Same as `Fast`, but skip downloading state proofs.
|
||||
#[structopt(long, value_name = "SYNC_MODE", default_value = "Full")]
|
||||
#[clap(long, arg_enum, value_name = "SYNC_MODE", default_value = "Full")]
|
||||
pub sync: SyncMode,
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
// 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 clap::Args;
|
||||
use sc_network::config::{identity::ed25519, NodeKeyConfig};
|
||||
use sp_core::H256;
|
||||
use std::{path::PathBuf, str::FromStr};
|
||||
use structopt::StructOpt;
|
||||
|
||||
use crate::{arg_enums::NodeKeyType, error};
|
||||
|
||||
@@ -30,7 +30,7 @@ const NODE_KEY_ED25519_FILE: &str = "secret_ed25519";
|
||||
|
||||
/// Parameters used to create the `NodeKeyConfig`, which determines the keypair
|
||||
/// used for libp2p networking.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct NodeKeyParams {
|
||||
/// The secret key to use for libp2p networking.
|
||||
///
|
||||
@@ -46,7 +46,7 @@ pub struct NodeKeyParams {
|
||||
/// WARNING: Secrets provided as command-line arguments are easily exposed.
|
||||
/// Use of this option should be limited to development and testing. To use
|
||||
/// an externally managed secret key, use `--node-key-file` instead.
|
||||
#[structopt(long = "node-key", value_name = "KEY")]
|
||||
#[clap(long, value_name = "KEY")]
|
||||
pub node_key: Option<String>,
|
||||
|
||||
/// The type of secret key to use for libp2p networking.
|
||||
@@ -66,13 +66,7 @@ pub struct NodeKeyParams {
|
||||
///
|
||||
/// The node's secret key determines the corresponding public key and hence the
|
||||
/// node's peer ID in the context of libp2p.
|
||||
#[structopt(
|
||||
long = "node-key-type",
|
||||
value_name = "TYPE",
|
||||
possible_values = &NodeKeyType::variants(),
|
||||
case_insensitive = true,
|
||||
default_value = "Ed25519"
|
||||
)]
|
||||
#[clap(long, value_name = "TYPE", arg_enum, ignore_case = true, default_value = "Ed25519")]
|
||||
pub node_key_type: NodeKeyType,
|
||||
|
||||
/// The file from which to read the node's secret key to use for libp2p networking.
|
||||
@@ -85,7 +79,7 @@ pub struct NodeKeyParams {
|
||||
///
|
||||
/// If the file does not exist, it is created with a newly generated secret key of
|
||||
/// the chosen type.
|
||||
#[structopt(long = "node-key-file", value_name = "FILE")]
|
||||
#[clap(long, value_name = "FILE")]
|
||||
pub node_key_file: Option<PathBuf>,
|
||||
}
|
||||
|
||||
@@ -128,14 +122,15 @@ fn parse_ed25519_secret(hex: &str) -> error::Result<sc_network::config::Ed25519S
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use clap::ArgEnum;
|
||||
use sc_network::config::identity::{ed25519, Keypair};
|
||||
use std::fs;
|
||||
|
||||
#[test]
|
||||
fn test_node_key_config_input() {
|
||||
fn secret_input(net_config_dir: &PathBuf) -> error::Result<()> {
|
||||
NodeKeyType::variants().iter().try_for_each(|t| {
|
||||
let node_key_type = NodeKeyType::from_str(t).unwrap();
|
||||
NodeKeyType::value_variants().iter().try_for_each(|t| {
|
||||
let node_key_type = *t;
|
||||
let sk = match node_key_type {
|
||||
NodeKeyType::Ed25519 => ed25519::SecretKey::generate().as_ref().to_vec(),
|
||||
};
|
||||
@@ -194,8 +189,8 @@ mod tests {
|
||||
where
|
||||
F: Fn(NodeKeyParams) -> error::Result<()>,
|
||||
{
|
||||
NodeKeyType::variants().iter().try_for_each(|t| {
|
||||
let node_key_type = NodeKeyType::from_str(t).unwrap();
|
||||
NodeKeyType::value_variants().iter().try_for_each(|t| {
|
||||
let node_key_type = *t;
|
||||
f(NodeKeyParams { node_key_type, node_key: None, node_key_file: None })
|
||||
})
|
||||
}
|
||||
|
||||
@@ -23,23 +23,23 @@
|
||||
//! targeted at handling input parameter parsing providing
|
||||
//! a reasonable abstraction.
|
||||
|
||||
use clap::Args;
|
||||
use sc_network::config::Role;
|
||||
use sc_service::config::OffchainWorkerConfig;
|
||||
use structopt::StructOpt;
|
||||
|
||||
use crate::{error, OffchainWorkerEnabled};
|
||||
|
||||
/// Offchain worker related parameters.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct OffchainWorkerParams {
|
||||
/// Should execute offchain workers on every block.
|
||||
///
|
||||
/// By default it's only enabled for nodes that are authoring new blocks.
|
||||
#[structopt(
|
||||
#[clap(
|
||||
long = "offchain-worker",
|
||||
value_name = "ENABLED",
|
||||
possible_values = &OffchainWorkerEnabled::variants(),
|
||||
case_insensitive = true,
|
||||
arg_enum,
|
||||
ignore_case = true,
|
||||
default_value = "WhenValidating"
|
||||
)]
|
||||
pub enabled: OffchainWorkerEnabled,
|
||||
@@ -48,7 +48,7 @@ pub struct OffchainWorkerParams {
|
||||
///
|
||||
/// Enables a runtime to write directly to a offchain workers
|
||||
/// DB during block import.
|
||||
#[structopt(long = "enable-offchain-indexing", value_name = "ENABLE_OFFCHAIN_INDEXING")]
|
||||
#[clap(long = "enable-offchain-indexing", value_name = "ENABLE_OFFCHAIN_INDEXING")]
|
||||
pub indexing_enabled: bool,
|
||||
}
|
||||
|
||||
|
||||
@@ -17,23 +17,23 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::error;
|
||||
use clap::Args;
|
||||
use sc_service::{KeepBlocks, PruningMode, Role};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// Parameters to define the pruning mode
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct PruningParams {
|
||||
/// Specify the state pruning mode, a number of blocks to keep or 'archive'.
|
||||
///
|
||||
/// Default is to keep all block states if the node is running as a
|
||||
/// validator (i.e. 'archive'), otherwise state is only kept for the last
|
||||
/// 256 blocks.
|
||||
#[structopt(long = "pruning", value_name = "PRUNING_MODE")]
|
||||
#[clap(long, value_name = "PRUNING_MODE")]
|
||||
pub pruning: Option<String>,
|
||||
/// Specify the number of finalized blocks to keep in the database.
|
||||
///
|
||||
/// Default is to keep all blocks.
|
||||
#[structopt(long, value_name = "COUNT")]
|
||||
#[clap(long, value_name = "COUNT")]
|
||||
pub keep_blocks: Option<u32>,
|
||||
}
|
||||
|
||||
|
||||
@@ -17,36 +17,36 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::arg_enums::TracingReceiver;
|
||||
use clap::Args;
|
||||
use sc_service::config::BasePath;
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// Shared parameters used by all `CoreParams`.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct SharedParams {
|
||||
/// Specify the chain specification.
|
||||
///
|
||||
/// It can be one of the predefined ones (dev, local, or staging) or it can be a path to a file
|
||||
/// with the chainspec (such as one exported by the `build-spec` subcommand).
|
||||
#[structopt(long, value_name = "CHAIN_SPEC")]
|
||||
#[clap(long, value_name = "CHAIN_SPEC")]
|
||||
pub chain: Option<String>,
|
||||
|
||||
/// Specify the development chain.
|
||||
///
|
||||
/// This flag sets `--chain=dev`, `--force-authoring`, `--rpc-cors=all`,
|
||||
/// `--alice`, and `--tmp` flags, unless explicitly overridden.
|
||||
#[structopt(long, conflicts_with_all = &["chain"])]
|
||||
#[clap(long, conflicts_with_all = &["chain"])]
|
||||
pub dev: bool,
|
||||
|
||||
/// Specify custom base path.
|
||||
#[structopt(long, short = "d", value_name = "PATH", parse(from_os_str))]
|
||||
#[clap(long, short = 'd', value_name = "PATH", parse(from_os_str))]
|
||||
pub base_path: Option<PathBuf>,
|
||||
|
||||
/// Sets a custom logging filter. Syntax is <target>=<level>, e.g. -lsync=debug.
|
||||
///
|
||||
/// Log levels (least to most verbose) are error, warn, info, debug, and trace.
|
||||
/// By default, all targets log `info`. The global log level can be set with -l<level>.
|
||||
#[structopt(short = "l", long, value_name = "LOG_PATTERN")]
|
||||
#[clap(short = 'l', long, value_name = "LOG_PATTERN")]
|
||||
pub log: Vec<String>,
|
||||
|
||||
/// Enable detailed log output.
|
||||
@@ -54,11 +54,11 @@ pub struct SharedParams {
|
||||
/// This includes displaying the log target, log level and thread name.
|
||||
///
|
||||
/// This is automatically enabled when something is logged with any higher level than `info`.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub detailed_log_output: bool,
|
||||
|
||||
/// Disable log color output.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub disable_log_color: bool,
|
||||
|
||||
/// Enable feature to dynamically update and reload the log filter.
|
||||
@@ -68,21 +68,15 @@ pub struct SharedParams {
|
||||
///
|
||||
/// The `system_addLogFilter` and `system_resetLogFilter` RPCs will have no effect with this
|
||||
/// option not being set.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
pub enable_log_reloading: bool,
|
||||
|
||||
/// Sets a custom profiling filter. Syntax is the same as for logging: <target>=<level>
|
||||
#[structopt(long = "tracing-targets", value_name = "TARGETS")]
|
||||
#[clap(long, value_name = "TARGETS")]
|
||||
pub tracing_targets: Option<String>,
|
||||
|
||||
/// Receiver to process tracing messages.
|
||||
#[structopt(
|
||||
long = "tracing-receiver",
|
||||
value_name = "RECEIVER",
|
||||
possible_values = &TracingReceiver::variants(),
|
||||
case_insensitive = true,
|
||||
default_value = "Log"
|
||||
)]
|
||||
#[clap(long, value_name = "RECEIVER", arg_enum, ignore_case = true, default_value = "Log")]
|
||||
pub tracing_receiver: TracingReceiver,
|
||||
}
|
||||
|
||||
|
||||
@@ -16,18 +16,18 @@
|
||||
// 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 clap::Args;
|
||||
use sc_service::config::TransactionPoolOptions;
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// Parameters used to create the pool configuration.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct TransactionPoolParams {
|
||||
/// Maximum number of transactions in the transaction pool.
|
||||
#[structopt(long = "pool-limit", value_name = "COUNT", default_value = "8192")]
|
||||
#[clap(long, value_name = "COUNT", default_value = "8192")]
|
||||
pub pool_limit: usize,
|
||||
|
||||
/// Maximum number of kilobytes of all transactions stored in the pool.
|
||||
#[structopt(long = "pool-kbytes", value_name = "COUNT", default_value = "20480")]
|
||||
#[clap(long, value_name = "COUNT", default_value = "20480")]
|
||||
pub pool_kbytes: usize,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user