mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 22:47:56 +00:00
ChainSpec trait (#5185)
* ChainSpec trait * Apply suggestions from code review Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Added docs * Fixed build * Fixed build Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use structopt::StructOpt;
|
||||
use sc_service::{Configuration, RuntimeGenesis, config::DatabaseConfig};
|
||||
use sc_service::{Configuration, config::DatabaseConfig};
|
||||
|
||||
use crate::error;
|
||||
use crate::arg_enums::{
|
||||
@@ -79,15 +79,12 @@ pub struct ImportParams {
|
||||
|
||||
impl ImportParams {
|
||||
/// Put block import CLI params into `config` object.
|
||||
pub fn update_config<G, E>(
|
||||
pub fn update_config(
|
||||
&self,
|
||||
mut config: &mut Configuration<G, E>,
|
||||
mut config: &mut Configuration,
|
||||
role: sc_service::Roles,
|
||||
is_dev: bool,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
G: RuntimeGenesis,
|
||||
{
|
||||
) -> error::Result<()> {
|
||||
use sc_client_api::execution_extensions::ExecutionStrategies;
|
||||
|
||||
if let Some(DatabaseConfig::Path { ref mut cache_size, .. }) = config.database {
|
||||
|
||||
@@ -21,7 +21,7 @@ use structopt::StructOpt;
|
||||
use sc_network::{
|
||||
config::{NonReservedPeerMode, TransportConfig}, multiaddr::Protocol,
|
||||
};
|
||||
use sc_service::{Configuration, RuntimeGenesis};
|
||||
use sc_service::Configuration;
|
||||
|
||||
use crate::error;
|
||||
use crate::params::node_key_params::NodeKeyParams;
|
||||
@@ -101,16 +101,13 @@ pub struct NetworkConfigurationParams {
|
||||
|
||||
impl NetworkConfigurationParams {
|
||||
/// Fill the given `NetworkConfiguration` by looking at the cli parameters.
|
||||
pub fn update_config<G, E>(
|
||||
pub fn update_config(
|
||||
&self,
|
||||
mut config: &mut Configuration<G, E>,
|
||||
mut config: &mut Configuration,
|
||||
config_path: PathBuf,
|
||||
client_id: String,
|
||||
is_dev: bool,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
G: RuntimeGenesis,
|
||||
{
|
||||
) -> error::Result<()> {
|
||||
config.network.boot_nodes.extend(self.bootnodes.clone());
|
||||
config.network.config_path = Some(config_path.clone());
|
||||
config.network.net_config_path = Some(config_path.clone());
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
use std::{path::PathBuf, str::FromStr};
|
||||
use structopt::StructOpt;
|
||||
use sc_service::{Configuration, RuntimeGenesis};
|
||||
use sc_service::Configuration;
|
||||
use sc_network::config::NodeKeyConfig;
|
||||
use sp_core::H256;
|
||||
|
||||
@@ -93,14 +93,11 @@ pub struct NodeKeyParams {
|
||||
impl NodeKeyParams {
|
||||
/// Create a `NodeKeyConfig` from the given `NodeKeyParams` in the context
|
||||
/// of an optional network config storage directory.
|
||||
pub fn update_config<'a, G, E>(
|
||||
pub fn update_config<'a>(
|
||||
&self,
|
||||
mut config: &'a mut Configuration<G, E>,
|
||||
mut config: &'a mut Configuration,
|
||||
net_config_path: Option<&PathBuf>,
|
||||
) -> error::Result<&'a NodeKeyConfig>
|
||||
where
|
||||
G: RuntimeGenesis,
|
||||
{
|
||||
) -> error::Result<&'a NodeKeyConfig> {
|
||||
config.network.node_key = match self.node_key_type {
|
||||
NodeKeyType::Ed25519 => {
|
||||
let secret = if let Some(node_key) = self.node_key.as_ref() {
|
||||
@@ -146,7 +143,7 @@ mod tests {
|
||||
fn test_node_key_config_input() {
|
||||
fn secret_input(net_config_dir: Option<&PathBuf>) -> error::Result<()> {
|
||||
NodeKeyType::variants().iter().try_for_each(|t| {
|
||||
let mut config = Configuration::<(), ()>::default();
|
||||
let mut config = Configuration::default();
|
||||
let node_key_type = NodeKeyType::from_str(t).unwrap();
|
||||
let sk = match node_key_type {
|
||||
NodeKeyType::Ed25519 => ed25519::SecretKey::generate().as_ref().to_vec()
|
||||
@@ -173,7 +170,7 @@ mod tests {
|
||||
fn test_node_key_config_file() {
|
||||
fn secret_file(net_config_dir: Option<&PathBuf>) -> error::Result<()> {
|
||||
NodeKeyType::variants().iter().try_for_each(|t| {
|
||||
let mut config = Configuration::<(), ()>::default();
|
||||
let mut config = Configuration::default();
|
||||
let node_key_type = NodeKeyType::from_str(t).unwrap();
|
||||
let tmp = tempfile::Builder::new().prefix("alice").tempdir()?;
|
||||
let file = tmp.path().join(format!("{}_mysecret", t)).to_path_buf();
|
||||
@@ -212,7 +209,7 @@ mod tests {
|
||||
|
||||
fn no_config_dir() -> error::Result<()> {
|
||||
with_def_params(|params| {
|
||||
let mut config = Configuration::<(), ()>::default();
|
||||
let mut config = Configuration::default();
|
||||
let typ = params.node_key_type;
|
||||
params.update_config(&mut config, None)
|
||||
.and_then(|c| match c {
|
||||
@@ -225,7 +222,7 @@ mod tests {
|
||||
|
||||
fn some_config_dir(net_config_dir: &PathBuf) -> error::Result<()> {
|
||||
with_def_params(|params| {
|
||||
let mut config = Configuration::<(), ()>::default();
|
||||
let mut config = Configuration::default();
|
||||
let dir = PathBuf::from(net_config_dir.clone());
|
||||
let typ = params.node_key_type;
|
||||
params.update_config(&mut config, Some(net_config_dir))
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use structopt::StructOpt;
|
||||
use sc_service::{Configuration, RuntimeGenesis, PruningMode};
|
||||
use sc_service::{Configuration, PruningMode};
|
||||
|
||||
use crate::error;
|
||||
|
||||
@@ -33,15 +33,12 @@ pub struct PruningParams {
|
||||
|
||||
impl PruningParams {
|
||||
/// Put block pruning CLI params into `config` object.
|
||||
pub fn update_config<G, E>(
|
||||
pub fn update_config(
|
||||
&self,
|
||||
mut config: &mut Configuration<G, E>,
|
||||
mut config: &mut Configuration,
|
||||
role: sc_service::Roles,
|
||||
unsafe_pruning: bool,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
G: RuntimeGenesis,
|
||||
{
|
||||
) -> error::Result<()> {
|
||||
// by default we disable pruning if the node is an authority (i.e.
|
||||
// `ArchiveAll`), otherwise we keep state for the last 256 blocks. if the
|
||||
// node is an authority and pruning is enabled explicitly, then we error
|
||||
|
||||
@@ -18,8 +18,7 @@ use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
use app_dirs::{AppInfo, AppDataType};
|
||||
use sc_service::{
|
||||
Configuration, ChainSpecExtension, RuntimeGenesis,
|
||||
config::DatabaseConfig, ChainSpec,
|
||||
Configuration, config::DatabaseConfig, ChainSpec,
|
||||
};
|
||||
|
||||
use crate::VersionInfo;
|
||||
@@ -50,25 +49,19 @@ pub struct SharedParams {
|
||||
|
||||
impl SharedParams {
|
||||
/// Load spec to `Configuration` from `SharedParams` and spec factory.
|
||||
pub fn update_config<'a, G, E, F>(
|
||||
pub fn update_config<'a, F>(
|
||||
&self,
|
||||
mut config: &'a mut Configuration<G, E>,
|
||||
mut config: &'a mut Configuration,
|
||||
spec_factory: F,
|
||||
version: &VersionInfo,
|
||||
) -> error::Result<&'a ChainSpec<G, E>> where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
F: FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
|
||||
) -> error::Result<&'a dyn ChainSpec> where
|
||||
F: FnOnce(&str) -> Result<Box<dyn ChainSpec>, String>,
|
||||
{
|
||||
let chain_key = match self.chain {
|
||||
Some(ref chain) => chain.clone(),
|
||||
None => if self.dev { "dev".into() } else { "".into() }
|
||||
};
|
||||
let spec = match spec_factory(&chain_key)? {
|
||||
Some(spec) => spec,
|
||||
None => ChainSpec::from_json_file(PathBuf::from(chain_key))?
|
||||
};
|
||||
|
||||
let spec = spec_factory(&chain_key)?;
|
||||
config.network.boot_nodes = spec.boot_nodes().to_vec();
|
||||
config.telemetry_endpoints = spec.telemetry_endpoints().clone();
|
||||
|
||||
@@ -87,7 +80,7 @@ impl SharedParams {
|
||||
});
|
||||
}
|
||||
|
||||
Ok(config.chain_spec.as_ref().unwrap())
|
||||
Ok(config.expect_chain_spec())
|
||||
}
|
||||
|
||||
/// Initialize substrate. This must be done only once.
|
||||
|
||||
@@ -31,9 +31,9 @@ pub struct TransactionPoolParams {
|
||||
|
||||
impl TransactionPoolParams {
|
||||
/// Fill the given `PoolConfiguration` by looking at the cli parameters.
|
||||
pub fn update_config<G, E>(
|
||||
pub fn update_config(
|
||||
&self,
|
||||
config: &mut Configuration<G, E>,
|
||||
config: &mut Configuration,
|
||||
) -> error::Result<()> {
|
||||
// ready queue
|
||||
config.transaction_pool.ready.count = self.pool_limit;
|
||||
|
||||
Reference in New Issue
Block a user