(params, spec_factory, version).map(|_| None)
+ }
+ params::CoreParams::Custom(params) => Ok(Some(params)),
+ }
}
/// Create a `NodeKeyConfig` from the given `NodeKeyParams` in the context
/// of an optional network config storage directory.
-fn node_key_config(params: NodeKeyParams, net_config_dir: &Option
)
- -> error::Result
+fn node_key_config(
+ params: NodeKeyParams,
+ net_config_dir: &Option
,
+) -> error::Result
where
- P: AsRef
+ P: AsRef,
{
- match params.node_key_type {
- NodeKeyType::Secp256k1 =>
- params.node_key.as_ref().map(parse_secp256k1_secret).unwrap_or_else(||
- Ok(params.node_key_file
- .or_else(|| net_config_file(net_config_dir, NODE_KEY_SECP256K1_FILE))
- .map(network::Secret::File)
- .unwrap_or(network::Secret::New)))
- .map(NodeKeyConfig::Secp256k1),
-
- NodeKeyType::Ed25519 =>
- params.node_key.as_ref().map(parse_ed25519_secret).unwrap_or_else(||
- Ok(params.node_key_file
- .or_else(|| net_config_file(net_config_dir, NODE_KEY_ED25519_FILE))
- .map(network::Secret::File)
- .unwrap_or(network::Secret::New)))
- .map(NodeKeyConfig::Ed25519)
- }
+ match params.node_key_type {
+ NodeKeyType::Secp256k1 => params
+ .node_key
+ .as_ref()
+ .map(parse_secp256k1_secret)
+ .unwrap_or_else(|| {
+ Ok(params
+ .node_key_file
+ .or_else(|| net_config_file(net_config_dir, NODE_KEY_SECP256K1_FILE))
+ .map(network::Secret::File)
+ .unwrap_or(network::Secret::New))
+ })
+ .map(NodeKeyConfig::Secp256k1),
+
+ NodeKeyType::Ed25519 => params
+ .node_key
+ .as_ref()
+ .map(parse_ed25519_secret)
+ .unwrap_or_else(|| {
+ Ok(params
+ .node_key_file
+ .or_else(|| net_config_file(net_config_dir, NODE_KEY_ED25519_FILE))
+ .map(network::Secret::File)
+ .unwrap_or(network::Secret::New))
+ })
+ .map(NodeKeyConfig::Ed25519),
+ }
}
fn net_config_file(net_config_dir: &Option
, name: &str) -> Option
where
- P: AsRef
+ P: AsRef,
{
- net_config_dir.as_ref().map(|d| d.as_ref().join(name))
+ net_config_dir.as_ref().map(|d| d.as_ref().join(name))
}
/// Create an error caused by an invalid node key argument.
fn invalid_node_key(e: impl std::fmt::Display) -> error::Error {
- input_err(format!("Invalid node key: {}", e))
+ input_err(format!("Invalid node key: {}", e))
}
/// Parse a Secp256k1 secret key from a hex string into a `network::Secret`.
fn parse_secp256k1_secret(hex: &String) -> error::Result {
- H256::from_str(hex).map_err(invalid_node_key).and_then(|bytes|
- network::identity::secp256k1::SecretKey::from_bytes(bytes)
- .map(network::Secret::Input)
- .map_err(invalid_node_key))
+ H256::from_str(hex)
+ .map_err(invalid_node_key)
+ .and_then(|bytes| {
+ network::identity::secp256k1::SecretKey::from_bytes(bytes)
+ .map(network::Secret::Input)
+ .map_err(invalid_node_key)
+ })
}
/// Parse a Ed25519 secret key from a hex string into a `network::Secret`.
fn parse_ed25519_secret(hex: &String) -> error::Result {
- H256::from_str(&hex).map_err(invalid_node_key).and_then(|bytes|
- network::identity::ed25519::SecretKey::from_bytes(bytes)
- .map(network::Secret::Input)
- .map_err(invalid_node_key))
+ H256::from_str(&hex)
+ .map_err(invalid_node_key)
+ .and_then(|bytes| {
+ network::identity::ed25519::SecretKey::from_bytes(bytes)
+ .map(network::Secret::Input)
+ .map_err(invalid_node_key)
+ })
}
/// Fill the given `PoolConfiguration` by looking at the cli parameters.
fn fill_transaction_pool_configuration(
- options: &mut FactoryFullConfiguration,
- params: TransactionPoolParams,
+ options: &mut FactoryFullConfiguration,
+ params: TransactionPoolParams,
) -> error::Result<()> {
- // ready queue
- options.transaction_pool.ready.count = params.pool_limit;
- options.transaction_pool.ready.total_bytes = params.pool_kbytes * 1024;
+ // ready queue
+ options.transaction_pool.ready.count = params.pool_limit;
+ options.transaction_pool.ready.total_bytes = params.pool_kbytes * 1024;
- // future queue
- let factor = 10;
- options.transaction_pool.future.count = params.pool_limit / factor;
- options.transaction_pool.future.total_bytes = params.pool_kbytes * 1024 / factor;
+ // future queue
+ let factor = 10;
+ options.transaction_pool.future.count = params.pool_limit / factor;
+ options.transaction_pool.future.total_bytes = params.pool_kbytes * 1024 / factor;
- Ok(())
+ Ok(())
}
/// Fill the given `NetworkConfiguration` by looking at the cli parameters.
fn fill_network_configuration(
- cli: NetworkConfigurationParams,
- base_path: &Path,
- chain_spec_id: &str,
- config: &mut NetworkConfiguration,
- client_id: String,
+ cli: NetworkConfigurationParams,
+ base_path: &Path,
+ chain_spec_id: &str,
+ config: &mut NetworkConfiguration,
+ client_id: String,
) -> error::Result<()> {
- config.boot_nodes.extend(cli.bootnodes.into_iter());
- config.config_path = Some(
- network_path(&base_path, chain_spec_id).to_string_lossy().into()
- );
- config.net_config_path = config.config_path.clone();
- config.reserved_nodes.extend(cli.reserved_nodes.into_iter());
- if !config.reserved_nodes.is_empty() {
- config.non_reserved_mode = NonReservedPeerMode::Deny;
- }
+ config.boot_nodes.extend(cli.bootnodes.into_iter());
+ config.config_path = Some(
+ network_path(&base_path, chain_spec_id)
+ .to_string_lossy()
+ .into(),
+ );
+ config.net_config_path = config.config_path.clone();
+ config.reserved_nodes.extend(cli.reserved_nodes.into_iter());
+ if !config.reserved_nodes.is_empty() {
+ config.non_reserved_mode = NonReservedPeerMode::Deny;
+ }
- for addr in cli.listen_addr.iter() {
- let addr = addr.parse().map_err(|_| "Invalid listen multiaddress")?;
- config.listen_addresses.push(addr);
- }
+ for addr in cli.listen_addr.iter() {
+ let addr = addr.parse().map_err(|_| "Invalid listen multiaddress")?;
+ config.listen_addresses.push(addr);
+ }
- if config.listen_addresses.is_empty() {
- let port = match cli.port {
- Some(port) => port,
- None => 30333,
- };
+ if config.listen_addresses.is_empty() {
+ let port = match cli.port {
+ Some(port) => port,
+ None => 30333,
+ };
- config.listen_addresses = vec![
- iter::once(Protocol::Ip4(Ipv4Addr::new(0, 0, 0, 0)))
- .chain(iter::once(Protocol::Tcp(port)))
- .collect()
- ];
- }
+ config.listen_addresses = vec![iter::once(Protocol::Ip4(Ipv4Addr::new(0, 0, 0, 0)))
+ .chain(iter::once(Protocol::Tcp(port)))
+ .collect()];
+ }
- config.public_addresses = Vec::new();
+ config.public_addresses = Vec::new();
- config.client_version = client_id;
- config.node_key = node_key_config(cli.node_key_params, &config.net_config_path)?;
+ config.client_version = client_id;
+ config.node_key = node_key_config(cli.node_key_params, &config.net_config_path)?;
- config.in_peers = cli.in_peers;
- config.out_peers = cli.out_peers;
+ config.in_peers = cli.in_peers;
+ config.out_peers = cli.out_peers;
- config.enable_mdns = !cli.no_mdns;
+ config.enable_mdns = !cli.no_mdns;
- Ok(())
+ Ok(())
}
fn create_run_node_config(
- cli: RunCmd, spec_factory: S, impl_name: &'static str, version: &VersionInfo
+ cli: RunCmd,
+ spec_factory: S,
+ impl_name: &'static str,
+ version: &VersionInfo,
) -> error::Result>
where
- F: ServiceFactory,
- S: FnOnce(&str) -> Result