mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 02:17:58 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -17,8 +17,8 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::arg_enums::Database;
|
||||
use structopt::StructOpt;
|
||||
use sc_service::TransactionStorageMode;
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// Parameters for block import.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
|
||||
@@ -16,16 +16,17 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::arg_enums::{
|
||||
ExecutionStrategy, WasmExecutionMethod, DEFAULT_EXECUTION_BLOCK_CONSTRUCTION,
|
||||
DEFAULT_EXECUTION_IMPORT_BLOCK, DEFAULT_EXECUTION_IMPORT_BLOCK_VALIDATOR,
|
||||
DEFAULT_EXECUTION_OFFCHAIN_WORKER, DEFAULT_EXECUTION_OTHER, DEFAULT_EXECUTION_SYNCING,
|
||||
use crate::{
|
||||
arg_enums::{
|
||||
ExecutionStrategy, WasmExecutionMethod, DEFAULT_EXECUTION_BLOCK_CONSTRUCTION,
|
||||
DEFAULT_EXECUTION_IMPORT_BLOCK, DEFAULT_EXECUTION_IMPORT_BLOCK_VALIDATOR,
|
||||
DEFAULT_EXECUTION_OFFCHAIN_WORKER, DEFAULT_EXECUTION_OTHER, DEFAULT_EXECUTION_SYNCING,
|
||||
},
|
||||
params::{DatabaseParams, PruningParams},
|
||||
};
|
||||
use crate::params::DatabaseParams;
|
||||
use crate::params::PruningParams;
|
||||
use sc_client_api::execution_extensions::ExecutionStrategies;
|
||||
use structopt::StructOpt;
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[cfg(feature = "wasmtime")]
|
||||
const WASM_METHOD_DEFAULT: &str = "Compiled";
|
||||
@@ -73,11 +74,7 @@ pub struct ImportParams {
|
||||
pub execution_strategies: ExecutionStrategiesParams,
|
||||
|
||||
/// Specify the state cache size.
|
||||
#[structopt(
|
||||
long = "state-cache-size",
|
||||
value_name = "Bytes",
|
||||
default_value = "67108864"
|
||||
)]
|
||||
#[structopt(long = "state-cache-size", value_name = "Bytes", default_value = "67108864")]
|
||||
pub state_cache_size: usize,
|
||||
}
|
||||
|
||||
@@ -102,11 +99,7 @@ impl ImportParams {
|
||||
pub fn execution_strategies(&self, is_dev: bool, is_validator: bool) -> ExecutionStrategies {
|
||||
let exec = &self.execution_strategies;
|
||||
let exec_all_or = |strat: Option<ExecutionStrategy>, default: ExecutionStrategy| {
|
||||
let default = if is_dev {
|
||||
ExecutionStrategy::Native
|
||||
} else {
|
||||
default
|
||||
};
|
||||
let default = if is_dev { ExecutionStrategy::Native } else { default };
|
||||
|
||||
exec.execution.unwrap_or_else(|| strat.unwrap_or(default)).into()
|
||||
};
|
||||
@@ -120,10 +113,14 @@ impl ImportParams {
|
||||
ExecutionStrategies {
|
||||
syncing: exec_all_or(exec.execution_syncing, DEFAULT_EXECUTION_SYNCING),
|
||||
importing: exec_all_or(exec.execution_import_block, default_execution_import_block),
|
||||
block_construction:
|
||||
exec_all_or(exec.execution_block_construction, DEFAULT_EXECUTION_BLOCK_CONSTRUCTION),
|
||||
offchain_worker:
|
||||
exec_all_or(exec.execution_offchain_worker, DEFAULT_EXECUTION_OFFCHAIN_WORKER),
|
||||
block_construction: exec_all_or(
|
||||
exec.execution_block_construction,
|
||||
DEFAULT_EXECUTION_BLOCK_CONSTRUCTION,
|
||||
),
|
||||
offchain_worker: exec_all_or(
|
||||
exec.execution_offchain_worker,
|
||||
DEFAULT_EXECUTION_OFFCHAIN_WORKER,
|
||||
),
|
||||
other: exec_all_or(exec.execution_other, DEFAULT_EXECUTION_OTHER),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,14 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::error::Result;
|
||||
use crate::{error, error::Result};
|
||||
use sc_service::config::KeystoreConfig;
|
||||
use std::{fs, path::{PathBuf, Path}};
|
||||
use structopt::StructOpt;
|
||||
use crate::error;
|
||||
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";
|
||||
@@ -81,8 +83,7 @@ impl KeystoreParams {
|
||||
#[cfg(target_os = "unknown")]
|
||||
None
|
||||
} else if let Some(ref file) = self.password_filename {
|
||||
let password = fs::read_to_string(file)
|
||||
.map_err(|e| format!("{}", e))?;
|
||||
let password = fs::read_to_string(file).map_err(|e| format!("{}", e))?;
|
||||
Some(SecretString::new(password))
|
||||
} else {
|
||||
self.password.clone()
|
||||
|
||||
@@ -25,21 +25,20 @@ mod pruning_params;
|
||||
mod shared_params;
|
||||
mod transaction_pool_params;
|
||||
|
||||
use std::{fmt::Debug, str::FromStr, convert::TryFrom};
|
||||
use sp_runtime::{generic::BlockId, traits::{Block as BlockT, NumberFor}};
|
||||
use crate::arg_enums::{CryptoScheme, OutputType};
|
||||
use sp_core::crypto::Ss58AddressFormat;
|
||||
use crate::arg_enums::{OutputType, CryptoScheme};
|
||||
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::*;
|
||||
pub use crate::params::import_params::*;
|
||||
pub use crate::params::keystore_params::*;
|
||||
pub use crate::params::network_params::*;
|
||||
pub use crate::params::node_key_params::*;
|
||||
pub use crate::params::offchain_worker_params::*;
|
||||
pub use crate::params::pruning_params::*;
|
||||
pub use crate::params::shared_params::*;
|
||||
pub use crate::params::transaction_pool_params::*;
|
||||
pub use crate::params::{
|
||||
database_params::*, import_params::*, keystore_params::*, network_params::*,
|
||||
node_key_params::*, offchain_worker_params::*, pruning_params::*, shared_params::*,
|
||||
transaction_pool_params::*,
|
||||
};
|
||||
|
||||
/// Wrapper type of `String` that holds an unsigned integer of arbitrary size, formatted as a decimal.
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -50,10 +49,7 @@ impl FromStr for GenericNumber {
|
||||
|
||||
fn from_str(block_number: &str) -> Result<Self, Self::Err> {
|
||||
if let Some(pos) = block_number.chars().position(|d| !d.is_digit(10)) {
|
||||
Err(format!(
|
||||
"Expected block number, found illegal digit at position: {}",
|
||||
pos,
|
||||
))
|
||||
Err(format!("Expected block number, found illegal digit at position: {}", pos,))
|
||||
} else {
|
||||
Ok(Self(block_number.to_owned()))
|
||||
}
|
||||
@@ -66,9 +62,9 @@ impl GenericNumber {
|
||||
/// See `https://doc.rust-lang.org/std/primitive.str.html#method.parse` for more elaborate
|
||||
/// documentation.
|
||||
pub fn parse<N>(&self) -> Result<N, String>
|
||||
where
|
||||
N: FromStr,
|
||||
N::Err: std::fmt::Debug,
|
||||
where
|
||||
N: FromStr,
|
||||
N::Err: std::fmt::Debug,
|
||||
{
|
||||
FromStr::from_str(&self.0).map_err(|e| format!("Failed to parse block number: {:?}", e))
|
||||
}
|
||||
@@ -109,7 +105,7 @@ impl BlockNumberOrHash {
|
||||
if self.0.starts_with("0x") {
|
||||
Ok(BlockId::Hash(
|
||||
FromStr::from_str(&self.0[2..])
|
||||
.map_err(|e| format!("Failed to parse block hash: {:?}", e))?
|
||||
.map_err(|e| format!("Failed to parse block hash: {:?}", e))?,
|
||||
))
|
||||
} else {
|
||||
GenericNumber(self.0.clone()).parse().map(BlockId::Number)
|
||||
@@ -117,7 +113,6 @@ impl BlockNumberOrHash {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Optional flag for specifying crypto algorithm
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
pub struct CryptoSchemeFlag {
|
||||
|
||||
@@ -16,13 +16,17 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::params::node_key_params::NodeKeyParams;
|
||||
use crate::arg_enums::SyncMode;
|
||||
use crate::{arg_enums::SyncMode, params::node_key_params::NodeKeyParams};
|
||||
use sc_network::{
|
||||
config::{NetworkConfiguration, NodeKeyConfig, NonReservedPeerMode, SetConfig, TransportConfig},
|
||||
config::{
|
||||
NetworkConfiguration, NodeKeyConfig, NonReservedPeerMode, SetConfig, TransportConfig,
|
||||
},
|
||||
multiaddr::Protocol,
|
||||
};
|
||||
use sc_service::{ChainSpec, ChainType, config::{Multiaddr, MultiaddrWithPeerId}};
|
||||
use sc_service::{
|
||||
config::{Multiaddr, MultiaddrWithPeerId},
|
||||
ChainSpec, ChainType,
|
||||
};
|
||||
use std::{borrow::Cow, path::PathBuf};
|
||||
use structopt::StructOpt;
|
||||
|
||||
@@ -97,11 +101,7 @@ pub struct NetworkParams {
|
||||
///
|
||||
/// 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"
|
||||
)]
|
||||
#[structopt(long = "max-parallel-downloads", value_name = "COUNT", default_value = "5")]
|
||||
pub max_parallel_downloads: u32,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
@@ -184,15 +184,16 @@ impl NetworkParams {
|
||||
let chain_type = chain_spec.chain_type();
|
||||
// Activate if the user explicitly requested local discovery, `--dev` is given or the
|
||||
// chain type is `Local`/`Development`
|
||||
let allow_non_globals_in_dht = self.discover_local
|
||||
|| is_dev
|
||||
|| matches!(chain_type, ChainType::Local | ChainType::Development);
|
||||
let allow_non_globals_in_dht =
|
||||
self.discover_local ||
|
||||
is_dev || matches!(chain_type, ChainType::Local | ChainType::Development);
|
||||
|
||||
let allow_private_ipv4 = match (self.allow_private_ipv4, self.no_private_ipv4) {
|
||||
(true, true) => unreachable!("`*_private_ipv4` flags are mutually exclusive; qed"),
|
||||
(true, false) => true,
|
||||
(false, true) => false,
|
||||
(false, false) => is_dev || matches!(chain_type, ChainType::Local | ChainType::Development),
|
||||
(false, false) =>
|
||||
is_dev || matches!(chain_type, ChainType::Local | ChainType::Development),
|
||||
};
|
||||
|
||||
NetworkConfiguration {
|
||||
|
||||
@@ -16,13 +16,12 @@
|
||||
// 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 sc_network::{config::identity::ed25519, config::NodeKeyConfig};
|
||||
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;
|
||||
use crate::error;
|
||||
use crate::{arg_enums::NodeKeyType, error};
|
||||
|
||||
/// The file name of the node's Ed25519 secret key inside the chain-specific
|
||||
/// network config directory, if neither `--node-key` nor `--node-key-file`
|
||||
@@ -103,12 +102,12 @@ impl NodeKeyParams {
|
||||
sc_network::config::Secret::File(
|
||||
self.node_key_file
|
||||
.clone()
|
||||
.unwrap_or_else(|| net_config_dir.join(NODE_KEY_ED25519_FILE))
|
||||
.unwrap_or_else(|| net_config_dir.join(NODE_KEY_ED25519_FILE)),
|
||||
)
|
||||
};
|
||||
|
||||
NodeKeyConfig::Ed25519(secret)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -120,13 +119,11 @@ fn invalid_node_key(e: impl std::fmt::Display) -> error::Error {
|
||||
|
||||
/// Parse a Ed25519 secret key from a hex string into a `sc_network::Secret`.
|
||||
fn parse_ed25519_secret(hex: &str) -> error::Result<sc_network::config::Ed25519Secret> {
|
||||
H256::from_str(&hex)
|
||||
.map_err(invalid_node_key)
|
||||
.and_then(|bytes| {
|
||||
ed25519::SecretKey::from_bytes(bytes)
|
||||
.map(sc_network::config::Secret::Input)
|
||||
.map_err(invalid_node_key)
|
||||
})
|
||||
H256::from_str(&hex).map_err(invalid_node_key).and_then(|bytes| {
|
||||
ed25519::SecretKey::from_bytes(bytes)
|
||||
.map(sc_network::config::Secret::Input)
|
||||
.map_err(invalid_node_key)
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -151,9 +148,7 @@ mod tests {
|
||||
params.node_key(net_config_dir).and_then(|c| match c {
|
||||
NodeKeyConfig::Ed25519(sc_network::config::Secret::Input(ref ski))
|
||||
if node_key_type == NodeKeyType::Ed25519 && &sk[..] == ski.as_ref() =>
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
Ok(()),
|
||||
_ => Err(error::Error::Input("Unexpected node key config".into())),
|
||||
})
|
||||
})
|
||||
@@ -171,14 +166,14 @@ mod tests {
|
||||
node_key_file: Some(file),
|
||||
};
|
||||
|
||||
let node_key = params.node_key(&PathBuf::from("not-used"))
|
||||
let node_key = params
|
||||
.node_key(&PathBuf::from("not-used"))
|
||||
.expect("Creates node key config")
|
||||
.into_keypair()
|
||||
.expect("Creates node key pair");
|
||||
|
||||
match node_key {
|
||||
Keypair::Ed25519(ref pair)
|
||||
if pair.secret().as_ref() == key.as_ref() => {}
|
||||
Keypair::Ed25519(ref pair) if pair.secret().as_ref() == key.as_ref() => {},
|
||||
_ => panic!("Invalid key"),
|
||||
}
|
||||
}
|
||||
@@ -202,11 +197,7 @@ mod tests {
|
||||
{
|
||||
NodeKeyType::variants().iter().try_for_each(|t| {
|
||||
let node_key_type = NodeKeyType::from_str(t).unwrap();
|
||||
f(NodeKeyParams {
|
||||
node_key_type,
|
||||
node_key: None,
|
||||
node_key_file: None,
|
||||
})
|
||||
f(NodeKeyParams { node_key_type, node_key: None, node_key_file: None })
|
||||
})
|
||||
}
|
||||
|
||||
@@ -214,17 +205,12 @@ mod tests {
|
||||
with_def_params(|params| {
|
||||
let dir = PathBuf::from(net_config_dir.clone());
|
||||
let typ = params.node_key_type;
|
||||
params
|
||||
.node_key(net_config_dir)
|
||||
.and_then(move |c| match c {
|
||||
NodeKeyConfig::Ed25519(sc_network::config::Secret::File(ref f))
|
||||
if typ == NodeKeyType::Ed25519
|
||||
&& f == &dir.join(NODE_KEY_ED25519_FILE) =>
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(error::Error::Input("Unexpected node key config".into())),
|
||||
})
|
||||
params.node_key(net_config_dir).and_then(move |c| match c {
|
||||
NodeKeyConfig::Ed25519(sc_network::config::Secret::File(ref f))
|
||||
if typ == NodeKeyType::Ed25519 && f == &dir.join(NODE_KEY_ED25519_FILE) =>
|
||||
Ok(()),
|
||||
_ => Err(error::Error::Input("Unexpected node key config".into())),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,7 @@ use sc_network::config::Role;
|
||||
use sc_service::config::OffchainWorkerConfig;
|
||||
use structopt::StructOpt;
|
||||
|
||||
use crate::error;
|
||||
use crate::OffchainWorkerEnabled;
|
||||
use crate::{error, OffchainWorkerEnabled};
|
||||
|
||||
/// Offchain worker related parameters.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
@@ -49,10 +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"
|
||||
)]
|
||||
#[structopt(long = "enable-offchain-indexing", value_name = "ENABLE_OFFCHAIN_INDEXING")]
|
||||
pub indexing_enabled: bool,
|
||||
}
|
||||
|
||||
@@ -67,9 +63,6 @@ impl OffchainWorkerParams {
|
||||
};
|
||||
|
||||
let indexing_enabled = self.indexing_enabled;
|
||||
Ok(OffchainWorkerConfig {
|
||||
enabled,
|
||||
indexing_enabled,
|
||||
})
|
||||
Ok(OffchainWorkerConfig { enabled, indexing_enabled })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::error;
|
||||
use sc_service::{PruningMode, Role, KeepBlocks};
|
||||
use sc_service::{KeepBlocks, PruningMode, Role};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// Parameters to define the pruning mode
|
||||
@@ -54,13 +54,13 @@ impl PruningParams {
|
||||
"Validators should run with state pruning disabled (i.e. archive). \
|
||||
You can ignore this check with `--unsafe-pruning`."
|
||||
.to_string(),
|
||||
));
|
||||
))
|
||||
}
|
||||
|
||||
PruningMode::keep_blocks(s.parse().map_err(|_| {
|
||||
error::Error::Input("Invalid pruning mode specified".to_string())
|
||||
})?)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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 crate::arg_enums::TracingReceiver;
|
||||
use sc_service::config::BasePath;
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
use crate::arg_enums::TracingReceiver;
|
||||
|
||||
/// Shared parameters used by all `CoreParams`.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
@@ -88,13 +88,12 @@ impl SharedParams {
|
||||
pub fn chain_id(&self, is_dev: bool) -> String {
|
||||
match self.chain {
|
||||
Some(ref chain) => chain.clone(),
|
||||
None => {
|
||||
None =>
|
||||
if is_dev {
|
||||
"dev".into()
|
||||
} else {
|
||||
"".into()
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user