Skip to content
Snippets Groups Projects
Commit b5c84371 authored by bgallois's avatar bgallois Committed by Hugo Trentesaux
Browse files

refactor client

parent 949716be
No related branches found
No related tags found
1 merge request!256Refactor node implementation
This commit is part of merge request !256. Comments created here will be created in the context of that merge request.
......@@ -62,6 +62,7 @@ pub mod runtime_executor {
pub use gdev_runtime as runtime;
#[cfg(feature = "gtest")]
pub use gtest_runtime as runtime;
use sc_executor::sp_wasm_interface::{Function, HostFunctionRegistry};
pub struct Executor;
......@@ -136,67 +137,23 @@ pub fn new_chain_ops(
),
ServiceError,
> {
match config.chain_spec.runtime_type() {
#[cfg(feature = "g1")]
RuntimeType::G1::G1 => {
let PartialComponents {
client,
backend,
import_queue,
task_manager,
..
} = new_partial::<g1_runtime::RuntimeApi, runtime_executor::G1Executor>(
config,
manual_consensus,
)?;
Ok((
Arc::new(Client::G1(client)),
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>(
} = new_partial::<runtime_executor::runtime::RuntimeApi, runtime_executor::Executor>(
config,
manual_consensus,
)?;
Ok((
Arc::new(Client::GTest(client)),
Arc::new(Client::Client(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<
FullBackend,
......
......@@ -145,12 +145,14 @@ impl<Api> RuntimeApiCollection for Api where
/// A client instance.
#[derive(Clone)]
pub enum Client {
#[cfg(feature = "g1")]
G1(Arc<super::FullClient<g1_runtime::RuntimeApi, super::runtime_executor::Executor>>),
#[cfg(feature = "gtest")]
GTest(Arc<super::FullClient<gtest_runtime::RuntimeApi, super::runtime_executor::Executor>>),
#[cfg(feature = "gdev")]
GDev(Arc<super::FullClient<gdev_runtime::RuntimeApi, super::runtime_executor::Executor>>),
Client(
Arc<
super::FullClient<
super::runtime_executor::runtime::RuntimeApi,
super::runtime_executor::Executor,
>,
>,
),
}
macro_rules! with_client {
......@@ -162,22 +164,8 @@ macro_rules! with_client {
}
} => {
match $self {
#[cfg(feature = "g1")]
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) => {
Self::Client($client) => {
#[allow(unused_imports)]
use gdev_runtime as runtime;
$( $code )*
}
}
......@@ -196,50 +184,32 @@ impl ClientHandle for Client {
}
}
#[cfg(feature = "g1")]
impl From<Arc<super::FullClient<g1_runtime::RuntimeApi, super::runtime_executor::Executor>>>
for Client
{
fn from(
client: Arc<super::FullClient<g1_runtime::RuntimeApi, super::runtime_executor::Executor>>,
) -> Self {
Self::G1(client)
}
}
#[cfg(feature = "gtest")]
impl From<Arc<super::FullClient<gtest_runtime::RuntimeApi, super::runtime_executor::Executor>>>
for Client
impl
From<
Arc<
super::FullClient<
super::runtime_executor::runtime::RuntimeApi,
super::runtime_executor::Executor,
>,
>,
> for Client
{
fn from(
client: Arc<
super::FullClient<gtest_runtime::RuntimeApi, super::runtime_executor::Executor>,
super::FullClient<
super::runtime_executor::runtime::RuntimeApi,
super::runtime_executor::Executor,
>,
>,
) -> Self {
Self::GTest(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)
Self::Client(client)
}
}
macro_rules! match_client {
($self:ident, $method:ident($($param:ident),*)) => {
match $self {
#[cfg(feature = "g1")]
Self::G1(client) => client.$method($($param),*),
#[cfg(feature = "gtest")]
Self::GTest(client) => client.$method($($param),*),
#[cfg(feature = "gdev")]
Self::GDev(client) => client.$method($($param),*),
Self::Client(client) => client.$method($($param),*),
}
};
}
......@@ -336,7 +306,7 @@ use gtest_runtime as runtime;
#[cfg(feature = "gtest")]
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 {
fn sign_call(
&self,
......
......@@ -33,6 +33,7 @@ pub use common_runtime::{
constants::*, entities::*, handlers::*, AccountId, Address, Balance, BlockNumber,
FullIdentificationOfImpl, GetCurrentEpochIndex, Hash, Header, IdtyIndex, Index, Signature,
};
pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_identity::{IdtyStatus, IdtyValue};
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.
Please register or to comment