mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-09 08:18:04 +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:
@@ -19,7 +19,7 @@ use log::{debug, info};
|
||||
use std::sync::Arc;
|
||||
use sc_service::{
|
||||
AbstractService, RpcSession, Roles, Configuration, config::{DatabaseConfig, KeystoreConfig},
|
||||
ChainSpec, RuntimeGenesis
|
||||
GenericChainSpec, RuntimeGenesis
|
||||
};
|
||||
use wasm_bindgen::prelude::*;
|
||||
use futures::{prelude::*, channel::{oneshot, mpsc}, future::{poll_fn, ok}, compat::*};
|
||||
@@ -34,11 +34,11 @@ pub use console_log::init_with_level as init_console_log;
|
||||
/// Create a service configuration from a chain spec.
|
||||
///
|
||||
/// This configuration contains good defaults for a browser light client.
|
||||
pub async fn browser_configuration<G, E>(chain_spec: ChainSpec<G, E>)
|
||||
-> Result<Configuration<G, E>, Box<dyn std::error::Error>>
|
||||
pub async fn browser_configuration<G, E>(chain_spec: GenericChainSpec<G, E>)
|
||||
-> Result<Configuration, Box<dyn std::error::Error>>
|
||||
where
|
||||
G: RuntimeGenesis,
|
||||
E: Extension,
|
||||
G: RuntimeGenesis + 'static,
|
||||
E: Extension + 'static,
|
||||
{
|
||||
let name = chain_spec.name().to_string();
|
||||
|
||||
@@ -46,7 +46,7 @@ where
|
||||
let mut config = Configuration::default();
|
||||
config.network.boot_nodes = chain_spec.boot_nodes().to_vec();
|
||||
config.telemetry_endpoints = chain_spec.telemetry_endpoints().clone();
|
||||
config.chain_spec = Some(chain_spec);
|
||||
config.chain_spec = Some(Box::new(chain_spec));
|
||||
config.network.transport = sc_network::config::TransportConfig::Normal {
|
||||
wasm_external_transport: Some(transport.clone()),
|
||||
allow_private_ipv4: true,
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::{fmt::Debug, path::PathBuf};
|
||||
use sp_runtime::{BuildStorage, traits::{Block as BlockT, Header as HeaderT, NumberFor}};
|
||||
use std::fmt::Debug;
|
||||
use sp_runtime::{traits::{Block as BlockT, Header as HeaderT, NumberFor}};
|
||||
use sc_client::StateMachine;
|
||||
use sc_cli::{ExecutionStrategy, WasmExecutionMethod, VersionInfo};
|
||||
use sc_client_db::BenchmarkingState;
|
||||
use sc_service::{RuntimeGenesis, ChainSpecExtension, Configuration, ChainSpec};
|
||||
use sc_service::{Configuration, ChainSpec};
|
||||
use sc_executor::{NativeExecutor, NativeExecutionDispatch};
|
||||
use codec::{Encode, Decode};
|
||||
use frame_benchmarking::BenchmarkResults;
|
||||
@@ -82,13 +82,11 @@ impl BenchmarkCmd {
|
||||
}
|
||||
|
||||
/// Runs the command and benchmarks the chain.
|
||||
pub fn run<G, E, BB, ExecDispatch>(
|
||||
pub fn run<BB, ExecDispatch>(
|
||||
self,
|
||||
config: Configuration<G, E>,
|
||||
config: Configuration,
|
||||
) -> sc_cli::Result<()>
|
||||
where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
BB: BlockT + Debug,
|
||||
<<<BB as BlockT>::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug,
|
||||
<BB as BlockT>::Hash: std::str::FromStr,
|
||||
@@ -164,21 +162,16 @@ impl BenchmarkCmd {
|
||||
}
|
||||
|
||||
/// Update and prepare a `Configuration` with command line parameters
|
||||
pub fn update_config<G, E>(
|
||||
pub fn update_config(
|
||||
&self,
|
||||
mut config: &mut Configuration<G, E>,
|
||||
spec_factory: impl FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
|
||||
mut config: &mut Configuration,
|
||||
spec_factory: impl FnOnce(&str) -> Result<Box<dyn ChainSpec>, String>,
|
||||
_version: &VersionInfo,
|
||||
) -> sc_cli::Result<()> where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
) -> sc_cli::Result<()>
|
||||
{
|
||||
// Configure chain spec.
|
||||
let chain_key = self.shared_params.chain.clone().unwrap_or("dev".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.chain_spec = Some(spec);
|
||||
|
||||
// Make sure to configure keystore.
|
||||
|
||||
Reference in New Issue
Block a user