mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 19:07:57 +00:00
client: helper to create standalone client without service (#4536)
This commit is contained in:
@@ -139,6 +139,82 @@ pub type TLightCallExecutor<TBl, TExecDisp> = sc_client::light::call_executor::G
|
||||
>,
|
||||
>;
|
||||
|
||||
type TFullParts<TBl, TRtApi, TExecDisp> = (
|
||||
TFullClient<TBl, TRtApi, TExecDisp>,
|
||||
Arc<TFullBackend<TBl>>,
|
||||
Arc<RwLock<sc_keystore::Store>>,
|
||||
);
|
||||
|
||||
/// Creates a new full client for the given config.
|
||||
pub fn new_full_client<TBl, TRtApi, TExecDisp, TCfg, TGen, TCSExt>(
|
||||
config: &Configuration<TCfg, TGen, TCSExt>,
|
||||
) -> Result<TFullClient<TBl, TRtApi, TExecDisp>, Error> where
|
||||
TBl: BlockT<Hash=H256>,
|
||||
TExecDisp: NativeExecutionDispatch,
|
||||
TGen: sp_runtime::BuildStorage + serde::Serialize + for<'de> serde::Deserialize<'de>,
|
||||
TCSExt: Extension,
|
||||
{
|
||||
new_full_parts(config).map(|parts| parts.0)
|
||||
}
|
||||
|
||||
fn new_full_parts<TBl, TRtApi, TExecDisp, TCfg, TGen, TCSExt>(
|
||||
config: &Configuration<TCfg, TGen, TCSExt>,
|
||||
) -> Result<TFullParts<TBl, TRtApi, TExecDisp>, Error> where
|
||||
TBl: BlockT<Hash=H256>,
|
||||
TExecDisp: NativeExecutionDispatch,
|
||||
TGen: sp_runtime::BuildStorage + serde::Serialize + for<'de> serde::Deserialize<'de>,
|
||||
TCSExt: Extension,
|
||||
{
|
||||
let keystore = Keystore::open(
|
||||
config.keystore_path.clone().ok_or("No basepath configured")?,
|
||||
config.keystore_password.clone()
|
||||
)?;
|
||||
|
||||
let executor = NativeExecutor::<TExecDisp>::new(
|
||||
config.wasm_method,
|
||||
config.default_heap_pages,
|
||||
);
|
||||
|
||||
let fork_blocks = config.chain_spec
|
||||
.extensions()
|
||||
.get::<sc_client::ForkBlocks<TBl>>()
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
|
||||
let (client, backend) = {
|
||||
let db_config = sc_client_db::DatabaseSettings {
|
||||
state_cache_size: config.state_cache_size,
|
||||
state_cache_child_ratio:
|
||||
config.state_cache_child_ratio.map(|v| (v, 100)),
|
||||
pruning: config.pruning.clone(),
|
||||
source: match &config.database {
|
||||
DatabaseConfig::Path { path, cache_size } =>
|
||||
sc_client_db::DatabaseSettingsSrc::Path {
|
||||
path: path.clone(),
|
||||
cache_size: cache_size.clone().map(|u| u as usize),
|
||||
},
|
||||
DatabaseConfig::Custom(db) =>
|
||||
sc_client_db::DatabaseSettingsSrc::Custom(db.clone()),
|
||||
},
|
||||
};
|
||||
|
||||
let extensions = sc_client_api::execution_extensions::ExecutionExtensions::new(
|
||||
config.execution_strategies.clone(),
|
||||
Some(keystore.clone()),
|
||||
);
|
||||
|
||||
sc_client_db::new_client(
|
||||
db_config,
|
||||
executor,
|
||||
&config.chain_spec,
|
||||
fork_blocks,
|
||||
extensions,
|
||||
)?
|
||||
};
|
||||
|
||||
Ok((client, backend, keystore))
|
||||
}
|
||||
|
||||
impl<TCfg, TGen, TCSExt> ServiceBuilder<(), (), TCfg, TGen, TCSExt, (), (), (), (), (), (), (), (), (), ()>
|
||||
where TGen: RuntimeGenesis, TCSExt: Extension {
|
||||
/// Start the service builder with a configuration.
|
||||
@@ -161,52 +237,7 @@ where TGen: RuntimeGenesis, TCSExt: Extension {
|
||||
(),
|
||||
TFullBackend<TBl>,
|
||||
>, Error> {
|
||||
let keystore = Keystore::open(
|
||||
config.keystore_path.clone().ok_or("No basepath configured")?,
|
||||
config.keystore_password.clone()
|
||||
)?;
|
||||
|
||||
let executor = NativeExecutor::<TExecDisp>::new(
|
||||
config.wasm_method,
|
||||
config.default_heap_pages,
|
||||
);
|
||||
|
||||
let fork_blocks = config.chain_spec
|
||||
.extensions()
|
||||
.get::<sc_client::ForkBlocks<TBl>>()
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
|
||||
let (client, backend) = {
|
||||
let db_config = sc_client_db::DatabaseSettings {
|
||||
state_cache_size: config.state_cache_size,
|
||||
state_cache_child_ratio:
|
||||
config.state_cache_child_ratio.map(|v| (v, 100)),
|
||||
pruning: config.pruning.clone(),
|
||||
source: match &config.database {
|
||||
DatabaseConfig::Path { path, cache_size } =>
|
||||
sc_client_db::DatabaseSettingsSrc::Path {
|
||||
path: path.clone(),
|
||||
cache_size: cache_size.clone().map(|u| u as usize),
|
||||
},
|
||||
DatabaseConfig::Custom(db) =>
|
||||
sc_client_db::DatabaseSettingsSrc::Custom(db.clone()),
|
||||
},
|
||||
};
|
||||
|
||||
let extensions = sc_client_api::execution_extensions::ExecutionExtensions::new(
|
||||
config.execution_strategies.clone(),
|
||||
Some(keystore.clone()),
|
||||
);
|
||||
|
||||
sc_client_db::new_client(
|
||||
db_config,
|
||||
executor,
|
||||
&config.chain_spec,
|
||||
fork_blocks,
|
||||
extensions,
|
||||
)?
|
||||
};
|
||||
let (client, backend, keystore) = new_full_parts(&config)?;
|
||||
|
||||
let client = Arc::new(client);
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ use sp_runtime::traits::{NumberFor, Block as BlockT};
|
||||
|
||||
pub use self::error::Error;
|
||||
pub use self::builder::{
|
||||
new_full_client,
|
||||
ServiceBuilder, ServiceBuilderCommand, TFullClient, TLightClient, TFullBackend, TLightBackend,
|
||||
TFullCallExecutor, TLightCallExecutor,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user