mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 01:41:03 +00:00
Allow using any polkadot client instead of enum Client (#1575)
* WIP Forked at: e91642361133dba084a9c9b3efa45fcb6cd3c5ca Parent branch: origin/rococo-branch * WIP Forked at: e91642361133dba084a9c9b3efa45fcb6cd3c5ca Parent branch: origin/rococo-branch * WIP Forked at: e91642361133dba084a9c9b3efa45fcb6cd3c5ca Parent branch: origin/rococo-branch * WIP Forked at: e91642361133dba084a9c9b3efa45fcb6cd3c5ca Parent branch: origin/rococo-branch * WIP Forked at: e91642361133dba084a9c9b3efa45fcb6cd3c5ca Parent branch: origin/rococo-branch * WIP Forked at: e91642361133dba084a9c9b3efa45fcb6cd3c5ca Parent branch: origin/rococo-branch * WIP Forked at: e91642361133dba084a9c9b3efa45fcb6cd3c5ca Parent branch: origin/rococo-branch * WIP Forked at: e91642361133dba084a9c9b3efa45fcb6cd3c5ca Parent branch: origin/rococo-branch * Apply suggestions from code review * WIP Forked at: e91642361133dba084a9c9b3efa45fcb6cd3c5ca Parent branch: origin/rococo-branch * WIP Forked at: e91642361133dba084a9c9b3efa45fcb6cd3c5ca Parent branch: origin/rococo-branch * WIP Forked at: e91642361133dba084a9c9b3efa45fcb6cd3c5ca Parent branch: origin/rococo-branch * CLEANUP Forked at: e91642361133dba084a9c9b3efa45fcb6cd3c5ca Parent branch: origin/rococo-branch * link in doc * doc
This commit is contained in:
@@ -118,6 +118,19 @@ pub trait ExecuteWithClient {
|
||||
Client: AbstractClient<Block, Backend, Api = Api> + 'static;
|
||||
}
|
||||
|
||||
/// A handle to a Polkadot client instance.
|
||||
///
|
||||
/// The Polkadot service supports multiple different runtimes (Westend, Polkadot itself, etc). As each runtime has a
|
||||
/// specialized client, we need to hide them behind a trait. This is this trait.
|
||||
///
|
||||
/// When wanting to work with the inner client, you need to use `execute_with`.
|
||||
///
|
||||
/// See [`ExecuteWithClient`](trait.ExecuteWithClient.html) for more information.
|
||||
pub trait ClientHandle {
|
||||
/// Execute the given something with the client.
|
||||
fn execute_with<T: ExecuteWithClient>(&self, t: T) -> T::Output;
|
||||
}
|
||||
|
||||
/// A client instance of Polkadot.
|
||||
///
|
||||
/// See [`ExecuteWithClient`] for more information.
|
||||
@@ -129,9 +142,8 @@ pub enum Client {
|
||||
Rococo(Arc<crate::FullClient<rococo_runtime::RuntimeApi, crate::RococoExecutor>>),
|
||||
}
|
||||
|
||||
impl Client {
|
||||
/// Execute the given something with the client.
|
||||
pub fn execute_with<T: ExecuteWithClient>(&self, t: T) -> T::Output {
|
||||
impl ClientHandle for Client {
|
||||
fn execute_with<T: ExecuteWithClient>(&self, t: T) -> T::Output {
|
||||
match self {
|
||||
Self::Polkadot(client) => {
|
||||
T::execute_with_client::<_, _, crate::FullBackend>(t, client.clone())
|
||||
|
||||
@@ -109,16 +109,25 @@ impl IdentifyVariant for Box<dyn ChainSpec> {
|
||||
}
|
||||
}
|
||||
|
||||
type FullBackend = service::TFullBackend<Block>;
|
||||
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
|
||||
type FullClient<RuntimeApi, Executor> = service::TFullClient<Block, RuntimeApi, Executor>;
|
||||
type FullGrandpaBlockImport<RuntimeApi, Executor> = grandpa::GrandpaBlockImport<
|
||||
/// Polkadot's full backend.
|
||||
pub type FullBackend = service::TFullBackend<Block>;
|
||||
|
||||
/// Polkadot's select chain.
|
||||
pub type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
|
||||
|
||||
/// Polkadot's full client.
|
||||
pub type FullClient<RuntimeApi, Executor> = service::TFullClient<Block, RuntimeApi, Executor>;
|
||||
|
||||
/// Polkadot's full Grandpa block import.
|
||||
pub type FullGrandpaBlockImport<RuntimeApi, Executor> = grandpa::GrandpaBlockImport<
|
||||
FullBackend, Block, FullClient<RuntimeApi, Executor>, FullSelectChain
|
||||
>;
|
||||
|
||||
type LightBackend = service::TLightBackendWithHash<Block, sp_runtime::traits::BlakeTwo256>;
|
||||
/// Polkadot's light backend.
|
||||
pub type LightBackend = service::TLightBackendWithHash<Block, sp_runtime::traits::BlakeTwo256>;
|
||||
|
||||
type LightClient<RuntimeApi, Executor> =
|
||||
/// Polkadot's light client.
|
||||
pub type LightClient<RuntimeApi, Executor> =
|
||||
service::TLightClientWithBackend<Block, RuntimeApi, Executor, LightBackend>;
|
||||
|
||||
#[cfg(feature = "full-node")]
|
||||
|
||||
Reference in New Issue
Block a user