diff --git a/substrate/node/cli/src/service.rs b/substrate/node/cli/src/service.rs index f3ce9baa2e..b1d1348069 100644 --- a/substrate/node/cli/src/service.rs +++ b/substrate/node/cli/src/service.rs @@ -44,6 +44,7 @@ construct_simple_protocol! { /// be able to perform chain operations. macro_rules! new_full_start { ($config:expr) => {{ + type RpcExtension = jsonrpc_core::IoHandler; let mut import_setup = None; let inherent_data_providers = inherents::InherentDataProviders::new(); let mut tasks_to_spawn = Vec::new(); @@ -82,14 +83,8 @@ macro_rules! new_full_start { Ok(import_queue) })? - .with_rpc_extensions(|client, pool| { - use node_rpc::accounts::{Accounts, AccountsApi}; - - let mut io = jsonrpc_core::IoHandler::::default(); - io.extend_with( - AccountsApi::to_delegate(Accounts::new(client, pool)) - ); - io + .with_rpc_extensions(|client, pool| -> RpcExtension { + node_rpc::create(client, pool) })?; (builder, import_setup, inherent_data_providers, tasks_to_spawn) @@ -227,6 +222,7 @@ pub fn new_light(config: Configuration Result { use futures::Future; + type RpcExtension = jsonrpc_core::IoHandler; let inherent_data_providers = InherentDataProviders::new(); let mut tasks_to_spawn = Vec::new(); @@ -268,20 +264,8 @@ pub fn new_light(config: Configuration RpcExtension { + node_rpc::create(client, pool) })? .build()?; diff --git a/substrate/node/rpc/src/lib.rs b/substrate/node/rpc/src/lib.rs index 0d23c40a34..43f723f796 100644 --- a/substrate/node/rpc/src/lib.rs +++ b/substrate/node/rpc/src/lib.rs @@ -29,6 +29,12 @@ #![warn(missing_docs)] +use std::sync::Arc; + +use node_primitives::{Block, AccountNonceApi, ContractsApi}; +use sr_primitives::traits::ProvideRuntimeApi; +use transaction_pool::txpool::{ChainApi, Pool}; + pub mod accounts; pub mod contracts; @@ -38,3 +44,27 @@ mod constants { /// This typically means that the runtime trapped. pub const RUNTIME_ERROR: i64 = 1; } + +/// Instantiate all RPC extensions. +pub fn create(client: Arc, pool: Arc>) -> jsonrpc_core::IoHandler where + C: ProvideRuntimeApi, + C: client::blockchain::HeaderBackend, + C: Send + Sync + 'static, + C::Api: AccountNonceApi + ContractsApi, + P: ChainApi + Sync + Send + 'static, + M: jsonrpc_core::Metadata + Default, +{ + use self::{ + accounts::{Accounts, AccountsApi}, + contracts::{Contracts, ContractsApi}, + }; + + let mut io = jsonrpc_core::IoHandler::default(); + io.extend_with( + AccountsApi::to_delegate(Accounts::new(client.clone(), pool)) + ); + io.extend_with( + ContractsApi::to_delegate(Contracts::new(client)) + ); + io +}