mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 22:01:04 +00:00
Implement runtime api client side directly in the runtime (#1094)
* Move `initialise_block` into `Core` trait as it is crucial calling the API functions * Switch to first version of new runtime API implementation * Fixes bug in tests * Reenable asserts * Directly use the `TestAPI` in the tests * Start improving the api traits :100644 100644 898aadc7 49217199 M Cargo.lock :100644 10064461570436465ed664 M core/client/src/backend.rs :100644 100644 5d0c886b 64d710fd M core/client/src/block_builder.rs :100644 100644 c447855e 5ecbe474 M core/client/src/client.rs :100644 100644139cef13f90dbf3d M core/client/src/error.rs :100644 100644 2800c503 3298e66a M core/client/src/runtime_api.rs :100644 100644affa1c5c809b08bc M core/primitives/src/lib.rs :100644 1006442877dfa9d5547413 M core/sr-api/Cargo.toml :100644 100644 9a49784d 6a625a03 M core/sr-api/src/lib.rs :100644 100644 7c28e1c7 a1a444a9 M core/sr-primitives/src/traits.rs :100644 1006442e113ab6dcc01a6d M srml/metadata/Cargo.toml :100644 100644ea722a700809531aM srml/metadata/src/lib.rs * Refactoring * Move `sr-api` into client and more refactoring * Fixes tests * Some documentation and cleanup * Fixes compilation after rebase * More refactoring and more documentation * Makes `substrate-client` compilable on `wasm` On `wasm` it basically just exports the runtime api stuff. * Fixes grumbles * Updates wasm files after rebasing the master * Remove TODO comment * Remove whitespaces * Fixes after rebasing master * Another rebase, another fix commit
This commit is contained in:
@@ -67,7 +67,7 @@ use parking_lot::{Mutex, RwLock};
|
||||
use keystore::Store as Keystore;
|
||||
use client::BlockchainEvents;
|
||||
use runtime_primitives::traits::{Header, As};
|
||||
use runtime_primitives::generic::{BlockId, SignedBlock};
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use exit_future::Signal;
|
||||
#[doc(hidden)]
|
||||
pub use tokio::runtime::TaskExecutor;
|
||||
@@ -87,8 +87,11 @@ pub use components::{ServiceFactory, FullBackend, FullExecutor, LightBackend,
|
||||
ComponentBlock, FullClient, LightClient, FullComponents, LightComponents,
|
||||
CodeExecutor, NetworkService, FactoryChainSpec, FactoryBlock,
|
||||
FactoryFullConfiguration, RuntimeGenesis, FactoryGenesis,
|
||||
ComponentExHash, ComponentExtrinsic, FactoryExtrinsic,
|
||||
ComponentExHash, ComponentExtrinsic, FactoryExtrinsic
|
||||
};
|
||||
use components::{StartRPC, CreateNetworkParams};
|
||||
#[doc(hidden)]
|
||||
pub use network::OnDemand;
|
||||
|
||||
const DEFAULT_PROTOCOL_ID: &'static str = "sup";
|
||||
|
||||
@@ -122,7 +125,7 @@ impl<Components> Service<Components>
|
||||
where
|
||||
Components: components::Components,
|
||||
<Components as components::Components>::Executor: std::clone::Clone,
|
||||
for<'de> SignedBlock<ComponentBlock<Components>>: ::serde::Deserialize<'de>,
|
||||
// <Components as components::Components>::RuntimeApi: client::runtime_api::BlockBuilder<<<Components as components::Components>::Factory as ServiceFactory>::Block, Error=client::error::Error, OverlayedChanges=client::runtime_api::OverlayedChanges> + Sync + Send + client::runtime_api::Core<<<Components as components::Components>::Factory as components::ServiceFactory>::Block, primitives::AuthorityId, Error=client::error::Error, OverlayedChanges=client::runtime_api::OverlayedChanges> + client::runtime_api::ConstructRuntimeApi<Block=<<Components as components::Components>::Factory as ServiceFactory>::Block> + client::runtime_api::Metadata<<<Components as components::Components>::Factory as components::ServiceFactory>::Block, Vec<u8>, Error=client::error::Error> + client::runtime_api::TaggedTransactionQueue<<<Components as components::Components>::Factory as components::ServiceFactory>::Block, Error=client::error::Error>,
|
||||
{
|
||||
/// Creates a new service.
|
||||
pub fn new(
|
||||
@@ -173,17 +176,10 @@ impl<Components> Service<Components>
|
||||
client: client.clone(),
|
||||
};
|
||||
|
||||
let network_params = network::Params {
|
||||
config: network::ProtocolConfig {
|
||||
roles: config.roles,
|
||||
},
|
||||
network_config: config.network,
|
||||
chain: client.clone(),
|
||||
on_demand: on_demand.clone()
|
||||
.map(|d| d as Arc<network::OnDemandService<ComponentBlock<Components>>>),
|
||||
transaction_pool: Arc::new(transaction_pool_adapter),
|
||||
specialization: network_protocol,
|
||||
};
|
||||
let network_params = Components::CreateNetworkParams::create_network_params(
|
||||
client.clone(), config.roles, config.network, on_demand.clone(),
|
||||
transaction_pool_adapter, network_protocol
|
||||
);
|
||||
|
||||
let mut protocol_id = network::ProtocolId::default();
|
||||
let protocol_id_full = config.chain_spec.protocol_id().unwrap_or(DEFAULT_PROTOCOL_ID).as_bytes();
|
||||
@@ -232,33 +228,13 @@ impl<Components> Service<Components>
|
||||
task_executor.spawn(events);
|
||||
}
|
||||
|
||||
// RPC
|
||||
let rpc_config = RpcConfig {
|
||||
chain_name: config.chain_spec.name().to_string(),
|
||||
properties: config.chain_spec.properties().clone(),
|
||||
impl_name: config.impl_name,
|
||||
impl_version: config.impl_version,
|
||||
};
|
||||
|
||||
let (rpc_http, rpc_ws) = {
|
||||
let handler = || {
|
||||
let client = client.clone();
|
||||
let subscriptions = rpc::apis::Subscriptions::new(task_executor.clone());
|
||||
let chain = rpc::apis::chain::Chain::new(client.clone(), subscriptions.clone());
|
||||
let state = rpc::apis::state::State::new(client.clone(), subscriptions.clone());
|
||||
let author = rpc::apis::author::Author::new(client.clone(), transaction_pool.clone(), subscriptions.clone());
|
||||
rpc::rpc_handler::<ComponentBlock<Components>, ComponentExHash<Components>, _, _, _, _>(
|
||||
state,
|
||||
chain,
|
||||
author,
|
||||
rpc_config.clone(),
|
||||
)
|
||||
};
|
||||
(
|
||||
maybe_start_server(config.rpc_http, |address| rpc::start_http(address, handler()))?,
|
||||
maybe_start_server(config.rpc_ws, |address| rpc::start_ws(address, handler()))?,
|
||||
)
|
||||
};
|
||||
// RPC
|
||||
let (rpc_http, rpc_ws) = Components::RPC::start_rpc(
|
||||
client.clone(), config.chain_spec.name().to_string(), config.impl_name,
|
||||
config.impl_version, config.rpc_http, config.rpc_ws, config.chain_spec.properties(),
|
||||
task_executor.clone(), transaction_pool.clone()
|
||||
)?;
|
||||
|
||||
let proposer = Arc::new(ProposerFactory {
|
||||
client: client.clone(),
|
||||
@@ -309,9 +285,7 @@ impl<Components> Service<Components>
|
||||
}
|
||||
}
|
||||
|
||||
impl<Components> Service<Components> where
|
||||
Components: components::Components,
|
||||
{
|
||||
impl<Components> Service<Components> where Components: components::Components {
|
||||
/// Get shared client instance.
|
||||
pub fn client(&self) -> Arc<ComponentClient<Components>> {
|
||||
self.client.clone()
|
||||
@@ -420,7 +394,7 @@ impl<C: Components> TransactionPoolAdapter<C> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: Components> network::TransactionPool<ComponentExHash<C>, ComponentBlock<C>> for TransactionPoolAdapter<C> {
|
||||
impl<C: Components> network::TransactionPool<ComponentExHash<C>, ComponentBlock<C>> for TransactionPoolAdapter<C> where <C as components::Components>::RuntimeApi: Send + Sync{
|
||||
fn transactions(&self) -> Vec<(ComponentExHash<C>, ComponentExtrinsic<C>)> {
|
||||
self.pool.ready()
|
||||
.map(|t| {
|
||||
@@ -468,41 +442,6 @@ impl<C: Components> network::TransactionPool<ComponentExHash<C>, ComponentBlock<
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a simple `Service` implementation.
|
||||
/// This `Service` just holds an instance to a `service::Service` and implements `Deref`.
|
||||
/// It also provides a `new` function that takes a `config` and a `TaskExecutor`.
|
||||
#[macro_export]
|
||||
macro_rules! construct_simple_service {
|
||||
(
|
||||
$name: ident
|
||||
) => {
|
||||
pub struct $name<C: $crate::Components> {
|
||||
inner: $crate::Arc<$crate::Service<C>>,
|
||||
}
|
||||
|
||||
impl<C: $crate::Components> $name<C> {
|
||||
fn new(
|
||||
config: FactoryFullConfiguration<C::Factory>,
|
||||
executor: $crate::TaskExecutor
|
||||
) -> $crate::Result<Self, $crate::Error> {
|
||||
Ok(
|
||||
Self {
|
||||
inner: $crate::Arc::new($crate::Service::new(config, executor)?)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: $crate::Components> $crate::Deref for $name<C> {
|
||||
type Target = $crate::Service<C>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Constructs a service factory with the given name that implements the `ServiceFactory` trait.
|
||||
/// The required parameters are required to be given in the exact order. Some parameters are followed
|
||||
/// by `{}` blocks. These blocks are required and used to initialize the given parameter.
|
||||
@@ -544,6 +483,7 @@ macro_rules! construct_service_factory {
|
||||
$(#[$attr:meta])*
|
||||
struct $name:ident {
|
||||
Block = $block:ty,
|
||||
RuntimeApi = $runtime_api:ty,
|
||||
NetworkProtocol = $protocol:ty { $( $protocol_init:tt )* },
|
||||
RuntimeDispatch = $dispatch:ty,
|
||||
FullTransactionPoolApi = $full_transaction:ty { $( $full_transaction_init:tt )* },
|
||||
@@ -564,6 +504,7 @@ macro_rules! construct_service_factory {
|
||||
#[allow(unused_variables)]
|
||||
impl $crate::ServiceFactory for $name {
|
||||
type Block = $block;
|
||||
type RuntimeApi = $runtime_api;
|
||||
type NetworkProtocol = $protocol;
|
||||
type RuntimeDispatch = $dispatch;
|
||||
type FullTransactionPoolApi = $full_transaction;
|
||||
|
||||
Reference in New Issue
Block a user