Make chain && state RPCs async (#3480)

* chain+state RPCs are async now

* wrapped too long lines

* create full/light RPC impls from service

* use ordering

* post-merge fix
This commit is contained in:
Svyatoslav Nikolsky
2019-09-01 03:20:10 +03:00
committed by Gavin Wood
parent 816e132cd7
commit 607ee0a4e4
26 changed files with 1859 additions and 721 deletions
@@ -23,6 +23,9 @@ use jsonrpc_core as rpc;
/// Chain RPC Result type.
pub type Result<T> = std::result::Result<T, Error>;
/// State RPC future Result type.
pub type FutureResult<T> = Box<dyn rpc::futures::Future<Item = T, Error = Error> + Send>;
/// Chain RPC errors.
#[derive(Debug, derive_more::Display, derive_more::From)]
pub enum Error {
+3 -3
View File
@@ -23,7 +23,7 @@ use jsonrpc_core::Result as RpcResult;
use jsonrpc_core::futures::Future;
use jsonrpc_derive::rpc;
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
use self::error::Result;
use self::error::{FutureResult, Result};
pub use self::gen_client::Client as ChainClient;
@@ -35,11 +35,11 @@ pub trait ChainApi<Number, Hash, Header, SignedBlock> {
/// Get header of a relay chain block.
#[rpc(name = "chain_getHeader")]
fn header(&self, hash: Option<Hash>) -> Result<Option<Header>>;
fn header(&self, hash: Option<Hash>) -> FutureResult<Option<Header>>;
/// Get header and body of a relay chain block.
#[rpc(name = "chain_getBlock")]
fn block(&self, hash: Option<Hash>) -> Result<Option<SignedBlock>>;
fn block(&self, hash: Option<Hash>) -> FutureResult<Option<SignedBlock>>;
/// Get hash of the n-th block in the canon chain.
///
@@ -22,6 +22,9 @@ use jsonrpc_core as rpc;
/// State RPC Result type.
pub type Result<T> = std::result::Result<T, Error>;
/// State RPC future Result type.
pub type FutureResult<T> = Box<dyn rpc::futures::Future<Item = T, Error = Error> + Send>;
/// State RPC errors.
#[derive(Debug, derive_more::Display, derive_more::From)]
pub enum Error {
+13 -13
View File
@@ -25,7 +25,7 @@ use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
use primitives::Bytes;
use primitives::storage::{StorageKey, StorageData, StorageChangeSet};
use runtime_version::RuntimeVersion;
use self::error::Result;
use self::error::FutureResult;
pub use self::gen_client::Client as StateClient;
@@ -37,23 +37,23 @@ pub trait StateApi<Hash> {
/// Call a contract at a block's state.
#[rpc(name = "state_call", alias("state_callAt"))]
fn call(&self, name: String, bytes: Bytes, hash: Option<Hash>) -> Result<Bytes>;
fn call(&self, name: String, bytes: Bytes, hash: Option<Hash>) -> FutureResult<Bytes>;
/// Returns the keys with prefix, leave empty to get all the keys
#[rpc(name = "state_getKeys")]
fn storage_keys(&self, prefix: StorageKey, hash: Option<Hash>) -> Result<Vec<StorageKey>>;
fn storage_keys(&self, prefix: StorageKey, hash: Option<Hash>) -> FutureResult<Vec<StorageKey>>;
/// Returns a storage entry at a specific block's state.
#[rpc(name = "state_getStorage", alias("state_getStorageAt"))]
fn storage(&self, key: StorageKey, hash: Option<Hash>) -> Result<Option<StorageData>>;
fn storage(&self, key: StorageKey, hash: Option<Hash>) -> FutureResult<Option<StorageData>>;
/// Returns the hash of a storage entry at a block's state.
#[rpc(name = "state_getStorageHash", alias("state_getStorageHashAt"))]
fn storage_hash(&self, key: StorageKey, hash: Option<Hash>) -> Result<Option<Hash>>;
fn storage_hash(&self, key: StorageKey, hash: Option<Hash>) -> FutureResult<Option<Hash>>;
/// Returns the size of a storage entry at a block's state.
#[rpc(name = "state_getStorageSize", alias("state_getStorageSizeAt"))]
fn storage_size(&self, key: StorageKey, hash: Option<Hash>) -> Result<Option<u64>>;
fn storage_size(&self, key: StorageKey, hash: Option<Hash>) -> FutureResult<Option<u64>>;
/// Returns the keys with prefix from a child storage, leave empty to get all the keys
#[rpc(name = "state_getChildKeys")]
@@ -62,7 +62,7 @@ pub trait StateApi<Hash> {
child_storage_key: StorageKey,
prefix: StorageKey,
hash: Option<Hash>
) -> Result<Vec<StorageKey>>;
) -> FutureResult<Vec<StorageKey>>;
/// Returns a child storage entry at a specific block's state.
#[rpc(name = "state_getChildStorage")]
@@ -71,7 +71,7 @@ pub trait StateApi<Hash> {
child_storage_key: StorageKey,
key: StorageKey,
hash: Option<Hash>
) -> Result<Option<StorageData>>;
) -> FutureResult<Option<StorageData>>;
/// Returns the hash of a child storage entry at a block's state.
#[rpc(name = "state_getChildStorageHash")]
@@ -80,7 +80,7 @@ pub trait StateApi<Hash> {
child_storage_key: StorageKey,
key: StorageKey,
hash: Option<Hash>
) -> Result<Option<Hash>>;
) -> FutureResult<Option<Hash>>;
/// Returns the size of a child storage entry at a block's state.
#[rpc(name = "state_getChildStorageSize")]
@@ -89,15 +89,15 @@ pub trait StateApi<Hash> {
child_storage_key: StorageKey,
key: StorageKey,
hash: Option<Hash>
) -> Result<Option<u64>>;
) -> FutureResult<Option<u64>>;
/// Returns the runtime metadata as an opaque blob.
#[rpc(name = "state_getMetadata")]
fn metadata(&self, hash: Option<Hash>) -> Result<Bytes>;
fn metadata(&self, hash: Option<Hash>) -> FutureResult<Bytes>;
/// Get the runtime version.
#[rpc(name = "state_getRuntimeVersion", alias("chain_getRuntimeVersion"))]
fn runtime_version(&self, hash: Option<Hash>) -> Result<RuntimeVersion>;
fn runtime_version(&self, hash: Option<Hash>) -> FutureResult<RuntimeVersion>;
/// Query historical storage entries (by key) starting from a block given as the second parameter.
///
@@ -109,7 +109,7 @@ pub trait StateApi<Hash> {
keys: Vec<StorageKey>,
block: Hash,
hash: Option<Hash>
) -> Result<Vec<StorageChangeSet<Hash>>>;
) -> FutureResult<Vec<StorageChangeSet<Hash>>>;
/// New runtime version subscription
#[pubsub(