client: helper to create standalone client without service (#4536)

This commit is contained in:
André Silva
2020-01-06 14:52:14 +00:00
committed by Gavin Wood
parent b462009f88
commit 4fa4dfb77b
2 changed files with 78 additions and 46 deletions
+52 -21
View File
@@ -139,28 +139,32 @@ pub type TLightCallExecutor<TBl, TExecDisp> = sc_client::light::call_executor::G
>, >,
>; >;
impl<TCfg, TGen, TCSExt> ServiceBuilder<(), (), TCfg, TGen, TCSExt, (), (), (), (), (), (), (), (), (), ()> type TFullParts<TBl, TRtApi, TExecDisp> = (
where TGen: RuntimeGenesis, TCSExt: Extension {
/// Start the service builder with a configuration.
pub fn new_full<TBl: BlockT<Hash=H256>, TRtApi, TExecDisp: NativeExecutionDispatch>(
config: Configuration<TCfg, TGen, TCSExt>
) -> Result<ServiceBuilder<
TBl,
TRtApi,
TCfg,
TGen,
TCSExt,
TFullClient<TBl, TRtApi, TExecDisp>, TFullClient<TBl, TRtApi, TExecDisp>,
Arc<OnDemand<TBl>>, Arc<TFullBackend<TBl>>,
(), Arc<RwLock<sc_keystore::Store>>,
(), );
BoxFinalityProofRequestBuilder<TBl>,
Arc<dyn FinalityProofProvider<TBl>>, /// 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
TFullBackend<TBl>, TBl: BlockT<Hash=H256>,
>, Error> { 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( let keystore = Keystore::open(
config.keystore_path.clone().ok_or("No basepath configured")?, config.keystore_path.clone().ok_or("No basepath configured")?,
config.keystore_password.clone() config.keystore_password.clone()
@@ -208,6 +212,33 @@ where TGen: RuntimeGenesis, TCSExt: Extension {
)? )?
}; };
Ok((client, backend, keystore))
}
impl<TCfg, TGen, TCSExt> ServiceBuilder<(), (), TCfg, TGen, TCSExt, (), (), (), (), (), (), (), (), (), ()>
where TGen: RuntimeGenesis, TCSExt: Extension {
/// Start the service builder with a configuration.
pub fn new_full<TBl: BlockT<Hash=H256>, TRtApi, TExecDisp: NativeExecutionDispatch>(
config: Configuration<TCfg, TGen, TCSExt>
) -> Result<ServiceBuilder<
TBl,
TRtApi,
TCfg,
TGen,
TCSExt,
TFullClient<TBl, TRtApi, TExecDisp>,
Arc<OnDemand<TBl>>,
(),
(),
BoxFinalityProofRequestBuilder<TBl>,
Arc<dyn FinalityProofProvider<TBl>>,
(),
(),
(),
TFullBackend<TBl>,
>, Error> {
let (client, backend, keystore) = new_full_parts(&config)?;
let client = Arc::new(client); let client = Arc::new(client);
Ok(ServiceBuilder { Ok(ServiceBuilder {
+1
View File
@@ -54,6 +54,7 @@ use sp_runtime::traits::{NumberFor, Block as BlockT};
pub use self::error::Error; pub use self::error::Error;
pub use self::builder::{ pub use self::builder::{
new_full_client,
ServiceBuilder, ServiceBuilderCommand, TFullClient, TLightClient, TFullBackend, TLightBackend, ServiceBuilder, ServiceBuilderCommand, TFullClient, TLightClient, TFullBackend, TLightBackend,
TFullCallExecutor, TLightCallExecutor, TFullCallExecutor, TLightCallExecutor,
}; };