Skip to content
Snippets Groups Projects
Unverified Commit a6efc7b6 authored by bgallois's avatar bgallois
Browse files

refactor client

parent e269e954
No related branches found
No related tags found
No related merge requests found
...@@ -62,6 +62,7 @@ pub mod runtime_executor { ...@@ -62,6 +62,7 @@ pub mod runtime_executor {
pub use gdev_runtime as runtime; pub use gdev_runtime as runtime;
#[cfg(feature = "gtest")] #[cfg(feature = "gtest")]
pub use gtest_runtime as runtime; pub use gtest_runtime as runtime;
use sc_executor::sp_wasm_interface::{Function, HostFunctionRegistry}; use sc_executor::sp_wasm_interface::{Function, HostFunctionRegistry};
pub struct Executor; pub struct Executor;
...@@ -136,66 +137,22 @@ pub fn new_chain_ops( ...@@ -136,66 +137,22 @@ pub fn new_chain_ops(
), ),
ServiceError, ServiceError,
> { > {
match config.chain_spec.runtime_type() { let PartialComponents {
#[cfg(feature = "g1")] client,
RuntimeType::G1::G1 => { backend,
let PartialComponents { import_queue,
client, task_manager,
backend, ..
import_queue, } = new_partial::<runtime_executor::runtime::RuntimeApi, runtime_executor::Executor>(
task_manager, config,
.. manual_consensus,
} = new_partial::<g1_runtime::RuntimeApi, runtime_executor::G1Executor>( )?;
config, Ok((
manual_consensus, Arc::new(Client::Client(client)),
)?; backend,
Ok(( import_queue,
Arc::new(Client::G1(client)), task_manager,
backend, ))
import_queue,
task_manager,
))
}
#[cfg(feature = "gtest")]
RuntimeType::GTest => {
let PartialComponents {
client,
backend,
import_queue,
task_manager,
..
} = new_partial::<gtest_runtime::RuntimeApi, runtime_executor::GTestExecutor>(
config,
manual_consensus,
)?;
Ok((
Arc::new(Client::GTest(client)),
backend,
import_queue,
task_manager,
))
}
#[cfg(feature = "gdev")]
RuntimeType::GDev => {
let PartialComponents {
client,
backend,
import_queue,
task_manager,
..
} = new_partial::<gdev_runtime::RuntimeApi, runtime_executor::Executor>(
config,
manual_consensus,
)?;
Ok((
Arc::new(Client::GDev(client)),
backend,
import_queue,
task_manager,
))
}
_ => panic!("unknown runtime"),
}
} }
type FullGrandpaBlockImport<RuntimeApi, Executor> = sc_consensus_grandpa::GrandpaBlockImport< type FullGrandpaBlockImport<RuntimeApi, Executor> = sc_consensus_grandpa::GrandpaBlockImport<
......
...@@ -145,12 +145,14 @@ impl<Api> RuntimeApiCollection for Api where ...@@ -145,12 +145,14 @@ impl<Api> RuntimeApiCollection for Api where
/// A client instance. /// A client instance.
#[derive(Clone)] #[derive(Clone)]
pub enum Client { pub enum Client {
#[cfg(feature = "g1")] Client(
G1(Arc<super::FullClient<g1_runtime::RuntimeApi, super::runtime_executor::Executor>>), Arc<
#[cfg(feature = "gtest")] super::FullClient<
GTest(Arc<super::FullClient<gtest_runtime::RuntimeApi, super::runtime_executor::Executor>>), super::runtime_executor::runtime::RuntimeApi,
#[cfg(feature = "gdev")] super::runtime_executor::Executor,
GDev(Arc<super::FullClient<gdev_runtime::RuntimeApi, super::runtime_executor::Executor>>), >,
>,
),
} }
macro_rules! with_client { macro_rules! with_client {
...@@ -162,22 +164,8 @@ macro_rules! with_client { ...@@ -162,22 +164,8 @@ macro_rules! with_client {
} }
} => { } => {
match $self { match $self {
#[cfg(feature = "g1")] Self::Client($client) => {
Self::G1($client) => {
#[allow(unused_imports)]
use g1_runtime as runtime;
$( $code )*
}
#[cfg(feature = "gtest")]
Self::GTest($client) => {
#[allow(unused_imports)]
use gtest_runtime as runtime;
$( $code )*
}
#[cfg(feature = "gdev")]
Self::GDev($client) => {
#[allow(unused_imports)] #[allow(unused_imports)]
use gdev_runtime as runtime;
$( $code )* $( $code )*
} }
} }
...@@ -196,50 +184,32 @@ impl ClientHandle for Client { ...@@ -196,50 +184,32 @@ impl ClientHandle for Client {
} }
} }
#[cfg(feature = "g1")] impl
impl From<Arc<super::FullClient<g1_runtime::RuntimeApi, super::runtime_executor::Executor>>> From<
for Client Arc<
{ super::FullClient<
fn from( super::runtime_executor::runtime::RuntimeApi,
client: Arc<super::FullClient<g1_runtime::RuntimeApi, super::runtime_executor::Executor>>, super::runtime_executor::Executor,
) -> Self { >,
Self::G1(client) >,
} > for Client
}
#[cfg(feature = "gtest")]
impl From<Arc<super::FullClient<gtest_runtime::RuntimeApi, super::runtime_executor::Executor>>>
for Client
{ {
fn from( fn from(
client: Arc< client: Arc<
super::FullClient<gtest_runtime::RuntimeApi, super::runtime_executor::Executor>, super::FullClient<
super::runtime_executor::runtime::RuntimeApi,
super::runtime_executor::Executor,
>,
>, >,
) -> Self { ) -> Self {
Self::GTest(client) Self::Client(client)
}
}
#[cfg(feature = "gdev")]
impl From<Arc<super::FullClient<gdev_runtime::RuntimeApi, super::runtime_executor::Executor>>>
for Client
{
fn from(
client: Arc<super::FullClient<gdev_runtime::RuntimeApi, super::runtime_executor::Executor>>,
) -> Self {
Self::GDev(client)
} }
} }
macro_rules! match_client { macro_rules! match_client {
($self:ident, $method:ident($($param:ident),*)) => { ($self:ident, $method:ident($($param:ident),*)) => {
match $self { match $self {
#[cfg(feature = "g1")] Self::Client(client) => client.$method($($param),*),
Self::G1(client) => client.$method($($param),*),
#[cfg(feature = "gtest")]
Self::GTest(client) => client.$method($($param),*),
#[cfg(feature = "gdev")]
Self::GDev(client) => client.$method($($param),*),
} }
}; };
} }
...@@ -336,7 +306,7 @@ use gtest_runtime as runtime; ...@@ -336,7 +306,7 @@ use gtest_runtime as runtime;
#[cfg(feature = "gtest")] #[cfg(feature = "gtest")]
type FullClient = super::FullClient<runtime::RuntimeApi, super::runtime_executor::Executor>; type FullClient = super::FullClient<runtime::RuntimeApi, super::runtime_executor::Executor>;
#[cfg(any(feature = "gdev", feature = "gtest"))] #[cfg(any(feature = "gdev", feature = "gtest", feature = "g1"))]
impl BenchmarkCallSigner<runtime::RuntimeCall, sp_core::sr25519::Pair> for FullClient { impl BenchmarkCallSigner<runtime::RuntimeCall, sp_core::sr25519::Pair> for FullClient {
fn sign_call( fn sign_call(
&self, &self,
......
...@@ -33,6 +33,7 @@ pub use common_runtime::{ ...@@ -33,6 +33,7 @@ pub use common_runtime::{
constants::*, entities::*, handlers::*, AccountId, Address, Balance, BlockNumber, constants::*, entities::*, handlers::*, AccountId, Address, Balance, BlockNumber,
FullIdentificationOfImpl, GetCurrentEpochIndex, Hash, Header, IdtyIndex, Index, Signature, FullIdentificationOfImpl, GetCurrentEpochIndex, Hash, Header, IdtyIndex, Index, Signature,
}; };
pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall; pub use pallet_balances::Call as BalancesCall;
pub use pallet_identity::{IdtyStatus, IdtyValue}; pub use pallet_identity::{IdtyStatus, IdtyValue};
pub use pallet_im_online::sr25519::AuthorityId as ImOnlineId; pub use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment