RPC: Mark storage methods as blocking (#11459)

* client/api: Make `storage_keys` blocking

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* client/api: Ensure `state_*` RPC methods are blocking

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* client/rpc: Ensure `childstate_*` RPC methods are blocking

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* client/rpc: `ChainApi` make RPC methods sync

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Remove unused async-traits

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* client/rpc-api: Make chain RPC methods blocking

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update client/rpc/src/state/state_full.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Add `blocking` to `state_getKeysPaged` RPC call

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Fix build and warning

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Remove `async_trait` tidyup

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Alexandru Vasile
2022-05-20 22:16:35 +03:00
committed by GitHub
parent 4a71017dd3
commit 87de1e7e0d
8 changed files with 163 additions and 222 deletions
+6 -6
View File
@@ -26,24 +26,24 @@ pub mod error;
#[rpc(client, server)] #[rpc(client, server)]
pub trait ChainApi<Number, Hash, Header, SignedBlock> { pub trait ChainApi<Number, Hash, Header, SignedBlock> {
/// Get header. /// Get header.
#[method(name = "chain_getHeader")] #[method(name = "chain_getHeader", blocking)]
async fn header(&self, hash: Option<Hash>) -> RpcResult<Option<Header>>; fn header(&self, hash: Option<Hash>) -> RpcResult<Option<Header>>;
/// Get header and body of a relay chain block. /// Get header and body of a relay chain block.
#[method(name = "chain_getBlock")] #[method(name = "chain_getBlock", blocking)]
async fn block(&self, hash: Option<Hash>) -> RpcResult<Option<SignedBlock>>; fn block(&self, hash: Option<Hash>) -> RpcResult<Option<SignedBlock>>;
/// Get hash of the n-th block in the canon chain. /// Get hash of the n-th block in the canon chain.
/// ///
/// By default returns latest block hash. /// By default returns latest block hash.
#[method(name = "chain_getBlockHash", aliases = ["chain_getHead"])] #[method(name = "chain_getBlockHash", aliases = ["chain_getHead"], blocking)]
fn block_hash( fn block_hash(
&self, &self,
hash: Option<ListOrValue<NumberOrHex>>, hash: Option<ListOrValue<NumberOrHex>>,
) -> RpcResult<ListOrValue<Option<Hash>>>; ) -> RpcResult<ListOrValue<Option<Hash>>>;
/// Get hash of the last finalized block in the canon chain. /// Get hash of the last finalized block in the canon chain.
#[method(name = "chain_getFinalizedHead", aliases = ["chain_getFinalisedHead"])] #[method(name = "chain_getFinalizedHead", aliases = ["chain_getFinalisedHead"], blocking)]
fn finalized_head(&self) -> RpcResult<Hash>; fn finalized_head(&self) -> RpcResult<Hash>;
/// All head subscription. /// All head subscription.
+14 -14
View File
@@ -28,9 +28,9 @@ use sp_core::storage::{PrefixedStorageKey, StorageData, StorageKey};
#[rpc(client, server)] #[rpc(client, server)]
pub trait ChildStateApi<Hash> { pub trait ChildStateApi<Hash> {
/// Returns the keys with prefix from a child storage, leave empty to get all the keys /// Returns the keys with prefix from a child storage, leave empty to get all the keys
#[method(name = "childstate_getKeys")] #[method(name = "childstate_getKeys", blocking)]
#[deprecated(since = "2.0.0", note = "Please use `getKeysPaged` with proper paging support")] #[deprecated(since = "2.0.0", note = "Please use `getKeysPaged` with proper paging support")]
async fn storage_keys( fn storage_keys(
&self, &self,
child_storage_key: PrefixedStorageKey, child_storage_key: PrefixedStorageKey,
prefix: StorageKey, prefix: StorageKey,
@@ -40,8 +40,8 @@ pub trait ChildStateApi<Hash> {
/// Returns the keys with prefix from a child storage with pagination support. /// Returns the keys with prefix from a child storage with pagination support.
/// Up to `count` keys will be returned. /// Up to `count` keys will be returned.
/// If `start_key` is passed, return next keys in storage in lexicographic order. /// If `start_key` is passed, return next keys in storage in lexicographic order.
#[method(name = "childstate_getKeysPaged", aliases = ["childstate_getKeysPagedAt"])] #[method(name = "childstate_getKeysPaged", aliases = ["childstate_getKeysPagedAt"], blocking)]
async fn storage_keys_paged( fn storage_keys_paged(
&self, &self,
child_storage_key: PrefixedStorageKey, child_storage_key: PrefixedStorageKey,
prefix: Option<StorageKey>, prefix: Option<StorageKey>,
@@ -51,8 +51,8 @@ pub trait ChildStateApi<Hash> {
) -> RpcResult<Vec<StorageKey>>; ) -> RpcResult<Vec<StorageKey>>;
/// Returns a child storage entry at a specific block's state. /// Returns a child storage entry at a specific block's state.
#[method(name = "childstate_getStorage")] #[method(name = "childstate_getStorage", blocking)]
async fn storage( fn storage(
&self, &self,
child_storage_key: PrefixedStorageKey, child_storage_key: PrefixedStorageKey,
key: StorageKey, key: StorageKey,
@@ -60,8 +60,8 @@ pub trait ChildStateApi<Hash> {
) -> RpcResult<Option<StorageData>>; ) -> RpcResult<Option<StorageData>>;
/// Returns child storage entries for multiple keys at a specific block's state. /// Returns child storage entries for multiple keys at a specific block's state.
#[method(name = "childstate_getStorageEntries")] #[method(name = "childstate_getStorageEntries", blocking)]
async fn storage_entries( fn storage_entries(
&self, &self,
child_storage_key: PrefixedStorageKey, child_storage_key: PrefixedStorageKey,
keys: Vec<StorageKey>, keys: Vec<StorageKey>,
@@ -69,8 +69,8 @@ pub trait ChildStateApi<Hash> {
) -> RpcResult<Vec<Option<StorageData>>>; ) -> RpcResult<Vec<Option<StorageData>>>;
/// Returns the hash of a child storage entry at a block's state. /// Returns the hash of a child storage entry at a block's state.
#[method(name = "childstate_getStorageHash")] #[method(name = "childstate_getStorageHash", blocking)]
async fn storage_hash( fn storage_hash(
&self, &self,
child_storage_key: PrefixedStorageKey, child_storage_key: PrefixedStorageKey,
key: StorageKey, key: StorageKey,
@@ -78,8 +78,8 @@ pub trait ChildStateApi<Hash> {
) -> RpcResult<Option<Hash>>; ) -> RpcResult<Option<Hash>>;
/// Returns the size of a child storage entry at a block's state. /// Returns the size of a child storage entry at a block's state.
#[method(name = "childstate_getStorageSize")] #[method(name = "childstate_getStorageSize", blocking)]
async fn storage_size( fn storage_size(
&self, &self,
child_storage_key: PrefixedStorageKey, child_storage_key: PrefixedStorageKey,
key: StorageKey, key: StorageKey,
@@ -87,8 +87,8 @@ pub trait ChildStateApi<Hash> {
) -> RpcResult<Option<u64>>; ) -> RpcResult<Option<u64>>;
/// Returns proof of storage for child key entries at a specific block's state. /// Returns proof of storage for child key entries at a specific block's state.
#[method(name = "state_getChildReadProof")] #[method(name = "state_getChildReadProof", blocking)]
async fn read_child_proof( fn read_child_proof(
&self, &self,
child_storage_key: PrefixedStorageKey, child_storage_key: PrefixedStorageKey,
keys: Vec<StorageKey>, keys: Vec<StorageKey>,
+26 -34
View File
@@ -34,21 +34,17 @@ pub use self::helpers::ReadProof;
#[rpc(client, server)] #[rpc(client, server)]
pub trait StateApi<Hash> { pub trait StateApi<Hash> {
/// Call a contract at a block's state. /// Call a contract at a block's state.
#[method(name = "state_call", aliases = ["state_callAt"])] #[method(name = "state_call", aliases = ["state_callAt"], blocking)]
async fn call(&self, name: String, bytes: Bytes, hash: Option<Hash>) -> RpcResult<Bytes>; fn call(&self, name: String, bytes: Bytes, hash: Option<Hash>) -> RpcResult<Bytes>;
/// Returns the keys with prefix, leave empty to get all the keys. /// Returns the keys with prefix, leave empty to get all the keys.
#[method(name = "state_getKeys")] #[method(name = "state_getKeys", blocking)]
#[deprecated(since = "2.0.0", note = "Please use `getKeysPaged` with proper paging support")] #[deprecated(since = "2.0.0", note = "Please use `getKeysPaged` with proper paging support")]
async fn storage_keys( fn storage_keys(&self, prefix: StorageKey, hash: Option<Hash>) -> RpcResult<Vec<StorageKey>>;
&self,
prefix: StorageKey,
hash: Option<Hash>,
) -> RpcResult<Vec<StorageKey>>;
/// Returns the keys with prefix, leave empty to get all the keys /// Returns the keys with prefix, leave empty to get all the keys
#[method(name = "state_getPairs")] #[method(name = "state_getPairs", blocking)]
async fn storage_pairs( fn storage_pairs(
&self, &self,
prefix: StorageKey, prefix: StorageKey,
hash: Option<Hash>, hash: Option<Hash>,
@@ -57,8 +53,8 @@ pub trait StateApi<Hash> {
/// Returns the keys with prefix with pagination support. /// Returns the keys with prefix with pagination support.
/// Up to `count` keys will be returned. /// Up to `count` keys will be returned.
/// If `start_key` is passed, return next keys in storage in lexicographic order. /// If `start_key` is passed, return next keys in storage in lexicographic order.
#[method(name = "state_getKeysPaged", aliases = ["state_getKeysPagedAt"])] #[method(name = "state_getKeysPaged", aliases = ["state_getKeysPagedAt"], blocking)]
async fn storage_keys_paged( fn storage_keys_paged(
&self, &self,
prefix: Option<StorageKey>, prefix: Option<StorageKey>,
count: u32, count: u32,
@@ -67,32 +63,32 @@ pub trait StateApi<Hash> {
) -> RpcResult<Vec<StorageKey>>; ) -> RpcResult<Vec<StorageKey>>;
/// Returns a storage entry at a specific block's state. /// Returns a storage entry at a specific block's state.
#[method(name = "state_getStorage", aliases = ["state_getStorageAt"])] #[method(name = "state_getStorage", aliases = ["state_getStorageAt"], blocking)]
async fn storage(&self, key: StorageKey, hash: Option<Hash>) -> RpcResult<Option<StorageData>>; fn storage(&self, key: StorageKey, hash: Option<Hash>) -> RpcResult<Option<StorageData>>;
/// Returns the hash of a storage entry at a block's state. /// Returns the hash of a storage entry at a block's state.
#[method(name = "state_getStorageHash", aliases = ["state_getStorageHashAt"])] #[method(name = "state_getStorageHash", aliases = ["state_getStorageHashAt"], blocking)]
async fn storage_hash(&self, key: StorageKey, hash: Option<Hash>) -> RpcResult<Option<Hash>>; fn storage_hash(&self, key: StorageKey, hash: Option<Hash>) -> RpcResult<Option<Hash>>;
/// Returns the size of a storage entry at a block's state. /// Returns the size of a storage entry at a block's state.
#[method(name = "state_getStorageSize", aliases = ["state_getStorageSizeAt"])] #[method(name = "state_getStorageSize", aliases = ["state_getStorageSizeAt"], blocking)]
async fn storage_size(&self, key: StorageKey, hash: Option<Hash>) -> RpcResult<Option<u64>>; fn storage_size(&self, key: StorageKey, hash: Option<Hash>) -> RpcResult<Option<u64>>;
/// Returns the runtime metadata as an opaque blob. /// Returns the runtime metadata as an opaque blob.
#[method(name = "state_getMetadata")] #[method(name = "state_getMetadata", blocking)]
async fn metadata(&self, hash: Option<Hash>) -> RpcResult<Bytes>; fn metadata(&self, hash: Option<Hash>) -> RpcResult<Bytes>;
/// Get the runtime version. /// Get the runtime version.
#[method(name = "state_getRuntimeVersion", aliases = ["chain_getRuntimeVersion"])] #[method(name = "state_getRuntimeVersion", aliases = ["chain_getRuntimeVersion"], blocking)]
async fn runtime_version(&self, hash: Option<Hash>) -> RpcResult<RuntimeVersion>; fn runtime_version(&self, hash: Option<Hash>) -> RpcResult<RuntimeVersion>;
/// Query historical storage entries (by key) starting from a block given as the second /// Query historical storage entries (by key) starting from a block given as the second
/// parameter. /// parameter.
/// ///
/// NOTE This first returned result contains the initial state of storage for all keys. /// NOTE This first returned result contains the initial state of storage for all keys.
/// Subsequent values in the vector represent changes to the previous state (diffs). /// Subsequent values in the vector represent changes to the previous state (diffs).
#[method(name = "state_queryStorage")] #[method(name = "state_queryStorage", blocking)]
async fn query_storage( fn query_storage(
&self, &self,
keys: Vec<StorageKey>, keys: Vec<StorageKey>,
block: Hash, block: Hash,
@@ -100,20 +96,16 @@ pub trait StateApi<Hash> {
) -> RpcResult<Vec<StorageChangeSet<Hash>>>; ) -> RpcResult<Vec<StorageChangeSet<Hash>>>;
/// Query storage entries (by key) starting at block hash given as the second parameter. /// Query storage entries (by key) starting at block hash given as the second parameter.
#[method(name = "state_queryStorageAt")] #[method(name = "state_queryStorageAt", blocking)]
async fn query_storage_at( fn query_storage_at(
&self, &self,
keys: Vec<StorageKey>, keys: Vec<StorageKey>,
at: Option<Hash>, at: Option<Hash>,
) -> RpcResult<Vec<StorageChangeSet<Hash>>>; ) -> RpcResult<Vec<StorageChangeSet<Hash>>>;
/// Returns proof of storage entries at a specific block's state. /// Returns proof of storage entries at a specific block's state.
#[method(name = "state_getReadProof")] #[method(name = "state_getReadProof", blocking)]
async fn read_proof( fn read_proof(&self, keys: Vec<StorageKey>, hash: Option<Hash>) -> RpcResult<ReadProof<Hash>>;
&self,
keys: Vec<StorageKey>,
hash: Option<Hash>,
) -> RpcResult<ReadProof<Hash>>;
/// New runtime version subscription /// New runtime version subscription
#[subscription( #[subscription(
@@ -285,8 +277,8 @@ pub trait StateApi<Hash> {
/// ///
/// If you are having issues with maximum payload size you can use the flag /// If you are having issues with maximum payload size you can use the flag
/// `-ltracing=trace` to get some logging during tracing. /// `-ltracing=trace` to get some logging during tracing.
#[method(name = "state_traceBlock")] #[method(name = "state_traceBlock", blocking)]
async fn trace_block( fn trace_block(
&self, &self,
block: Hash, block: Hash,
targets: Option<String>, targets: Option<String>,
+3 -4
View File
@@ -26,7 +26,7 @@ use futures::{
future::{self, FutureExt}, future::{self, FutureExt},
stream::{self, Stream, StreamExt}, stream::{self, Stream, StreamExt},
}; };
use jsonrpsee::{core::async_trait, PendingSubscription}; use jsonrpsee::PendingSubscription;
use sc_client_api::{BlockBackend, BlockchainEvents}; use sc_client_api::{BlockBackend, BlockchainEvents};
use sp_blockchain::HeaderBackend; use sp_blockchain::HeaderBackend;
use sp_runtime::{ use sp_runtime::{
@@ -51,7 +51,6 @@ impl<Block: BlockT, Client> FullChain<Block, Client> {
} }
} }
#[async_trait]
impl<Block, Client> ChainBackend<Client, Block> for FullChain<Block, Client> impl<Block, Client> ChainBackend<Client, Block> for FullChain<Block, Client>
where where
Block: BlockT + 'static, Block: BlockT + 'static,
@@ -62,11 +61,11 @@ where
&self.client &self.client
} }
async fn header(&self, hash: Option<Block::Hash>) -> Result<Option<Block::Header>, Error> { fn header(&self, hash: Option<Block::Hash>) -> Result<Option<Block::Header>, Error> {
self.client.header(BlockId::Hash(self.unwrap_or_best(hash))).map_err(client_err) self.client.header(BlockId::Hash(self.unwrap_or_best(hash))).map_err(client_err)
} }
async fn block(&self, hash: Option<Block::Hash>) -> Result<Option<SignedBlock<Block>>, Error> { fn block(&self, hash: Option<Block::Hash>) -> Result<Option<SignedBlock<Block>>, Error> {
self.client.block(&BlockId::Hash(self.unwrap_or_best(hash))).map_err(client_err) self.client.block(&BlockId::Hash(self.unwrap_or_best(hash))).map_err(client_err)
} }
+7 -12
View File
@@ -27,10 +27,7 @@ use std::sync::Arc;
use crate::SubscriptionTaskExecutor; use crate::SubscriptionTaskExecutor;
use jsonrpsee::{ use jsonrpsee::{core::RpcResult, PendingSubscription};
core::{async_trait, RpcResult},
PendingSubscription,
};
use sc_client_api::BlockchainEvents; use sc_client_api::BlockchainEvents;
use sp_rpc::{list::ListOrValue, number::NumberOrHex}; use sp_rpc::{list::ListOrValue, number::NumberOrHex};
use sp_runtime::{ use sp_runtime::{
@@ -45,7 +42,6 @@ pub use sc_rpc_api::chain::*;
use sp_blockchain::HeaderBackend; use sp_blockchain::HeaderBackend;
/// Blockchain backend API /// Blockchain backend API
#[async_trait]
trait ChainBackend<Client, Block: BlockT>: Send + Sync + 'static trait ChainBackend<Client, Block: BlockT>: Send + Sync + 'static
where where
Block: BlockT + 'static, Block: BlockT + 'static,
@@ -64,10 +60,10 @@ where
} }
/// Get header of a relay chain block. /// Get header of a relay chain block.
async fn header(&self, hash: Option<Block::Hash>) -> Result<Option<Block::Header>, Error>; fn header(&self, hash: Option<Block::Hash>) -> Result<Option<Block::Header>, Error>;
/// Get header and body of a relay chain block. /// Get header and body of a relay chain block.
async fn block(&self, hash: Option<Block::Hash>) -> Result<Option<SignedBlock<Block>>, Error>; fn block(&self, hash: Option<Block::Hash>) -> Result<Option<SignedBlock<Block>>, Error>;
/// Get hash of the n-th block in the canon chain. /// Get hash of the n-th block in the canon chain.
/// ///
@@ -126,7 +122,6 @@ pub struct Chain<Block: BlockT, Client> {
backend: Box<dyn ChainBackend<Client, Block>>, backend: Box<dyn ChainBackend<Client, Block>>,
} }
#[async_trait]
impl<Block, Client> ChainApiServer<NumberFor<Block>, Block::Hash, Block::Header, SignedBlock<Block>> impl<Block, Client> ChainApiServer<NumberFor<Block>, Block::Hash, Block::Header, SignedBlock<Block>>
for Chain<Block, Client> for Chain<Block, Client>
where where
@@ -134,12 +129,12 @@ where
Block::Header: Unpin, Block::Header: Unpin,
Client: HeaderBackend<Block> + BlockchainEvents<Block> + 'static, Client: HeaderBackend<Block> + BlockchainEvents<Block> + 'static,
{ {
async fn header(&self, hash: Option<Block::Hash>) -> RpcResult<Option<Block::Header>> { fn header(&self, hash: Option<Block::Hash>) -> RpcResult<Option<Block::Header>> {
self.backend.header(hash).await.map_err(Into::into) self.backend.header(hash).map_err(Into::into)
} }
async fn block(&self, hash: Option<Block::Hash>) -> RpcResult<Option<SignedBlock<Block>>> { fn block(&self, hash: Option<Block::Hash>) -> RpcResult<Option<SignedBlock<Block>>> {
self.backend.block(hash).await.map_err(Into::into) self.backend.block(hash).map_err(Into::into)
} }
fn block_hash( fn block_hash(
+58 -78
View File
@@ -28,7 +28,7 @@ use std::sync::Arc;
use crate::SubscriptionTaskExecutor; use crate::SubscriptionTaskExecutor;
use jsonrpsee::{ use jsonrpsee::{
core::{async_trait, Error as JsonRpseeError, RpcResult}, core::{Error as JsonRpseeError, RpcResult},
ws_server::PendingSubscription, ws_server::PendingSubscription,
}; };
@@ -53,14 +53,13 @@ use sp_blockchain::{HeaderBackend, HeaderMetadata};
const STORAGE_KEYS_PAGED_MAX_COUNT: u32 = 1000; const STORAGE_KEYS_PAGED_MAX_COUNT: u32 = 1000;
/// State backend API. /// State backend API.
#[async_trait]
pub trait StateBackend<Block: BlockT, Client>: Send + Sync + 'static pub trait StateBackend<Block: BlockT, Client>: Send + Sync + 'static
where where
Block: BlockT + 'static, Block: BlockT + 'static,
Client: Send + Sync + 'static, Client: Send + Sync + 'static,
{ {
/// Call runtime method at given block. /// Call runtime method at given block.
async fn call( fn call(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
method: String, method: String,
@@ -68,21 +67,21 @@ where
) -> Result<Bytes, Error>; ) -> Result<Bytes, Error>;
/// Returns the keys with prefix, leave empty to get all the keys. /// Returns the keys with prefix, leave empty to get all the keys.
async fn storage_keys( fn storage_keys(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
prefix: StorageKey, prefix: StorageKey,
) -> Result<Vec<StorageKey>, Error>; ) -> Result<Vec<StorageKey>, Error>;
/// Returns the keys with prefix along with their values, leave empty to get all the pairs. /// Returns the keys with prefix along with their values, leave empty to get all the pairs.
async fn storage_pairs( fn storage_pairs(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
prefix: StorageKey, prefix: StorageKey,
) -> Result<Vec<(StorageKey, StorageData)>, Error>; ) -> Result<Vec<(StorageKey, StorageData)>, Error>;
/// Returns the keys with prefix with pagination support. /// Returns the keys with prefix with pagination support.
async fn storage_keys_paged( fn storage_keys_paged(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
prefix: Option<StorageKey>, prefix: Option<StorageKey>,
@@ -91,14 +90,14 @@ where
) -> Result<Vec<StorageKey>, Error>; ) -> Result<Vec<StorageKey>, Error>;
/// Returns a storage entry at a specific block's state. /// Returns a storage entry at a specific block's state.
async fn storage( fn storage(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
key: StorageKey, key: StorageKey,
) -> Result<Option<StorageData>, Error>; ) -> Result<Option<StorageData>, Error>;
/// Returns the hash of a storage entry at a block's state. /// Returns the hash of a storage entry at a block's state.
async fn storage_hash( fn storage_hash(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
key: StorageKey, key: StorageKey,
@@ -108,24 +107,24 @@ where
/// ///
/// If data is available at `key`, it is returned. Else, the sum of values who's key has `key` /// If data is available at `key`, it is returned. Else, the sum of values who's key has `key`
/// prefix is returned, i.e. all the storage (double) maps that have this prefix. /// prefix is returned, i.e. all the storage (double) maps that have this prefix.
async fn storage_size( fn storage_size(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
key: StorageKey, key: StorageKey,
) -> Result<Option<u64>, Error>; ) -> Result<Option<u64>, Error>;
/// Returns the runtime metadata as an opaque blob. /// Returns the runtime metadata as an opaque blob.
async fn metadata(&self, block: Option<Block::Hash>) -> Result<Bytes, Error>; fn metadata(&self, block: Option<Block::Hash>) -> Result<Bytes, Error>;
/// Get the runtime version. /// Get the runtime version.
async fn runtime_version(&self, block: Option<Block::Hash>) -> Result<RuntimeVersion, Error>; fn runtime_version(&self, block: Option<Block::Hash>) -> Result<RuntimeVersion, Error>;
/// Query historical storage entries (by key) starting from a block given as the second /// Query historical storage entries (by key) starting from a block given as the second
/// parameter. /// parameter.
/// ///
/// NOTE This first returned result contains the initial state of storage for all keys. /// NOTE This first returned result contains the initial state of storage for all keys.
/// Subsequent values in the vector represent changes to the previous state (diffs). /// Subsequent values in the vector represent changes to the previous state (diffs).
async fn query_storage( fn query_storage(
&self, &self,
from: Block::Hash, from: Block::Hash,
to: Option<Block::Hash>, to: Option<Block::Hash>,
@@ -133,21 +132,21 @@ where
) -> Result<Vec<StorageChangeSet<Block::Hash>>, Error>; ) -> Result<Vec<StorageChangeSet<Block::Hash>>, Error>;
/// Query storage entries (by key) starting at block hash given as the second parameter. /// Query storage entries (by key) starting at block hash given as the second parameter.
async fn query_storage_at( fn query_storage_at(
&self, &self,
keys: Vec<StorageKey>, keys: Vec<StorageKey>,
at: Option<Block::Hash>, at: Option<Block::Hash>,
) -> Result<Vec<StorageChangeSet<Block::Hash>>, Error>; ) -> Result<Vec<StorageChangeSet<Block::Hash>>, Error>;
/// Returns proof of storage entries at a specific block's state. /// Returns proof of storage entries at a specific block's state.
async fn read_proof( fn read_proof(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
keys: Vec<StorageKey>, keys: Vec<StorageKey>,
) -> Result<ReadProof<Block::Hash>, Error>; ) -> Result<ReadProof<Block::Hash>, Error>;
/// Trace storage changes for block /// Trace storage changes for block
async fn trace_block( fn trace_block(
&self, &self,
block: Block::Hash, block: Block::Hash,
targets: Option<String>, targets: Option<String>,
@@ -203,39 +202,33 @@ pub struct StateApi<Block, Client> {
deny_unsafe: DenyUnsafe, deny_unsafe: DenyUnsafe,
} }
#[async_trait]
impl<Block, Client> StateApiServer<Block::Hash> for StateApi<Block, Client> impl<Block, Client> StateApiServer<Block::Hash> for StateApi<Block, Client>
where where
Block: BlockT + 'static, Block: BlockT + 'static,
Client: Send + Sync + 'static, Client: Send + Sync + 'static,
{ {
async fn call( fn call(&self, method: String, data: Bytes, block: Option<Block::Hash>) -> RpcResult<Bytes> {
&self, self.backend.call(block, method, data).map_err(Into::into)
method: String,
data: Bytes,
block: Option<Block::Hash>,
) -> RpcResult<Bytes> {
self.backend.call(block, method, data).await.map_err(Into::into)
} }
async fn storage_keys( fn storage_keys(
&self, &self,
key_prefix: StorageKey, key_prefix: StorageKey,
block: Option<Block::Hash>, block: Option<Block::Hash>,
) -> RpcResult<Vec<StorageKey>> { ) -> RpcResult<Vec<StorageKey>> {
self.backend.storage_keys(block, key_prefix).await.map_err(Into::into) self.backend.storage_keys(block, key_prefix).map_err(Into::into)
} }
async fn storage_pairs( fn storage_pairs(
&self, &self,
key_prefix: StorageKey, key_prefix: StorageKey,
block: Option<Block::Hash>, block: Option<Block::Hash>,
) -> RpcResult<Vec<(StorageKey, StorageData)>> { ) -> RpcResult<Vec<(StorageKey, StorageData)>> {
self.deny_unsafe.check_if_safe()?; self.deny_unsafe.check_if_safe()?;
self.backend.storage_pairs(block, key_prefix).await.map_err(Into::into) self.backend.storage_pairs(block, key_prefix).map_err(Into::into)
} }
async fn storage_keys_paged( fn storage_keys_paged(
&self, &self,
prefix: Option<StorageKey>, prefix: Option<StorageKey>,
count: u32, count: u32,
@@ -250,66 +243,61 @@ where
} }
self.backend self.backend
.storage_keys_paged(block, prefix, count, start_key) .storage_keys_paged(block, prefix, count, start_key)
.await
.map_err(Into::into) .map_err(Into::into)
} }
async fn storage( fn storage(
&self, &self,
key: StorageKey, key: StorageKey,
block: Option<Block::Hash>, block: Option<Block::Hash>,
) -> RpcResult<Option<StorageData>> { ) -> RpcResult<Option<StorageData>> {
self.backend.storage(block, key).await.map_err(Into::into) self.backend.storage(block, key).map_err(Into::into)
} }
async fn storage_hash( fn storage_hash(
&self, &self,
key: StorageKey, key: StorageKey,
block: Option<Block::Hash>, block: Option<Block::Hash>,
) -> RpcResult<Option<Block::Hash>> { ) -> RpcResult<Option<Block::Hash>> {
self.backend.storage_hash(block, key).await.map_err(Into::into) self.backend.storage_hash(block, key).map_err(Into::into)
} }
async fn storage_size( fn storage_size(&self, key: StorageKey, block: Option<Block::Hash>) -> RpcResult<Option<u64>> {
&self, self.backend.storage_size(block, key).map_err(Into::into)
key: StorageKey,
block: Option<Block::Hash>,
) -> RpcResult<Option<u64>> {
self.backend.storage_size(block, key).await.map_err(Into::into)
} }
async fn metadata(&self, block: Option<Block::Hash>) -> RpcResult<Bytes> { fn metadata(&self, block: Option<Block::Hash>) -> RpcResult<Bytes> {
self.backend.metadata(block).await.map_err(Into::into) self.backend.metadata(block).map_err(Into::into)
} }
async fn runtime_version(&self, at: Option<Block::Hash>) -> RpcResult<RuntimeVersion> { fn runtime_version(&self, at: Option<Block::Hash>) -> RpcResult<RuntimeVersion> {
self.backend.runtime_version(at).await.map_err(Into::into) self.backend.runtime_version(at).map_err(Into::into)
} }
async fn query_storage( fn query_storage(
&self, &self,
keys: Vec<StorageKey>, keys: Vec<StorageKey>,
from: Block::Hash, from: Block::Hash,
to: Option<Block::Hash>, to: Option<Block::Hash>,
) -> RpcResult<Vec<StorageChangeSet<Block::Hash>>> { ) -> RpcResult<Vec<StorageChangeSet<Block::Hash>>> {
self.deny_unsafe.check_if_safe()?; self.deny_unsafe.check_if_safe()?;
self.backend.query_storage(from, to, keys).await.map_err(Into::into) self.backend.query_storage(from, to, keys).map_err(Into::into)
} }
async fn query_storage_at( fn query_storage_at(
&self, &self,
keys: Vec<StorageKey>, keys: Vec<StorageKey>,
at: Option<Block::Hash>, at: Option<Block::Hash>,
) -> RpcResult<Vec<StorageChangeSet<Block::Hash>>> { ) -> RpcResult<Vec<StorageChangeSet<Block::Hash>>> {
self.backend.query_storage_at(keys, at).await.map_err(Into::into) self.backend.query_storage_at(keys, at).map_err(Into::into)
} }
async fn read_proof( fn read_proof(
&self, &self,
keys: Vec<StorageKey>, keys: Vec<StorageKey>,
block: Option<Block::Hash>, block: Option<Block::Hash>,
) -> RpcResult<ReadProof<Block::Hash>> { ) -> RpcResult<ReadProof<Block::Hash>> {
self.backend.read_proof(block, keys).await.map_err(Into::into) self.backend.read_proof(block, keys).map_err(Into::into)
} }
/// Re-execute the given block with the tracing targets given in `targets` /// Re-execute the given block with the tracing targets given in `targets`
@@ -317,7 +305,7 @@ where
/// ///
/// Note: requires the node to run with `--rpc-methods=Unsafe`. /// Note: requires the node to run with `--rpc-methods=Unsafe`.
/// Note: requires runtimes compiled with wasm tracing support, `--features with-tracing`. /// Note: requires runtimes compiled with wasm tracing support, `--features with-tracing`.
async fn trace_block( fn trace_block(
&self, &self,
block: Block::Hash, block: Block::Hash,
targets: Option<String>, targets: Option<String>,
@@ -327,7 +315,6 @@ where
self.deny_unsafe.check_if_safe()?; self.deny_unsafe.check_if_safe()?;
self.backend self.backend
.trace_block(block, targets, storage_keys, methods) .trace_block(block, targets, storage_keys, methods)
.await
.map_err(Into::into) .map_err(Into::into)
} }
@@ -348,14 +335,13 @@ where
} }
/// Child state backend API. /// Child state backend API.
#[async_trait]
pub trait ChildStateBackend<Block: BlockT, Client>: Send + Sync + 'static pub trait ChildStateBackend<Block: BlockT, Client>: Send + Sync + 'static
where where
Block: BlockT + 'static, Block: BlockT + 'static,
Client: Send + Sync + 'static, Client: Send + Sync + 'static,
{ {
/// Returns proof of storage for a child key entries at a specific block's state. /// Returns proof of storage for a child key entries at a specific block's state.
async fn read_child_proof( fn read_child_proof(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
@@ -364,7 +350,7 @@ where
/// Returns the keys with prefix from a child storage, /// Returns the keys with prefix from a child storage,
/// leave prefix empty to get all the keys. /// leave prefix empty to get all the keys.
async fn storage_keys( fn storage_keys(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
@@ -372,7 +358,7 @@ where
) -> Result<Vec<StorageKey>, Error>; ) -> Result<Vec<StorageKey>, Error>;
/// Returns the keys with prefix from a child storage with pagination support. /// Returns the keys with prefix from a child storage with pagination support.
async fn storage_keys_paged( fn storage_keys_paged(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
@@ -382,7 +368,7 @@ where
) -> Result<Vec<StorageKey>, Error>; ) -> Result<Vec<StorageKey>, Error>;
/// Returns a child storage entry at a specific block's state. /// Returns a child storage entry at a specific block's state.
async fn storage( fn storage(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
@@ -390,7 +376,7 @@ where
) -> Result<Option<StorageData>, Error>; ) -> Result<Option<StorageData>, Error>;
/// Returns child storage entries at a specific block's state. /// Returns child storage entries at a specific block's state.
async fn storage_entries( fn storage_entries(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
@@ -398,7 +384,7 @@ where
) -> Result<Vec<Option<StorageData>>, Error>; ) -> Result<Vec<Option<StorageData>>, Error>;
/// Returns the hash of a child storage entry at a block's state. /// Returns the hash of a child storage entry at a block's state.
async fn storage_hash( fn storage_hash(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
@@ -406,13 +392,13 @@ where
) -> Result<Option<Block::Hash>, Error>; ) -> Result<Option<Block::Hash>, Error>;
/// Returns the size of a child storage entry at a block's state. /// Returns the size of a child storage entry at a block's state.
async fn storage_size( fn storage_size(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
key: StorageKey, key: StorageKey,
) -> Result<Option<u64>, Error> { ) -> Result<Option<u64>, Error> {
self.storage(block, storage_key, key).await.map(|x| x.map(|x| x.0.len() as u64)) self.storage(block, storage_key, key).map(|x| x.map(|x| x.0.len() as u64))
} }
} }
@@ -421,25 +407,21 @@ pub struct ChildState<Block, Client> {
backend: Box<dyn ChildStateBackend<Block, Client>>, backend: Box<dyn ChildStateBackend<Block, Client>>,
} }
#[async_trait]
impl<Block, Client> ChildStateApiServer<Block::Hash> for ChildState<Block, Client> impl<Block, Client> ChildStateApiServer<Block::Hash> for ChildState<Block, Client>
where where
Block: BlockT + 'static, Block: BlockT + 'static,
Client: Send + Sync + 'static, Client: Send + Sync + 'static,
{ {
async fn storage_keys( fn storage_keys(
&self, &self,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
key_prefix: StorageKey, key_prefix: StorageKey,
block: Option<Block::Hash>, block: Option<Block::Hash>,
) -> RpcResult<Vec<StorageKey>> { ) -> RpcResult<Vec<StorageKey>> {
self.backend self.backend.storage_keys(block, storage_key, key_prefix).map_err(Into::into)
.storage_keys(block, storage_key, key_prefix)
.await
.map_err(Into::into)
} }
async fn storage_keys_paged( fn storage_keys_paged(
&self, &self,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
prefix: Option<StorageKey>, prefix: Option<StorageKey>,
@@ -449,47 +431,46 @@ where
) -> RpcResult<Vec<StorageKey>> { ) -> RpcResult<Vec<StorageKey>> {
self.backend self.backend
.storage_keys_paged(block, storage_key, prefix, count, start_key) .storage_keys_paged(block, storage_key, prefix, count, start_key)
.await
.map_err(Into::into) .map_err(Into::into)
} }
async fn storage( fn storage(
&self, &self,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
key: StorageKey, key: StorageKey,
block: Option<Block::Hash>, block: Option<Block::Hash>,
) -> RpcResult<Option<StorageData>> { ) -> RpcResult<Option<StorageData>> {
self.backend.storage(block, storage_key, key).await.map_err(Into::into) self.backend.storage(block, storage_key, key).map_err(Into::into)
} }
async fn storage_entries( fn storage_entries(
&self, &self,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
keys: Vec<StorageKey>, keys: Vec<StorageKey>,
block: Option<Block::Hash>, block: Option<Block::Hash>,
) -> RpcResult<Vec<Option<StorageData>>> { ) -> RpcResult<Vec<Option<StorageData>>> {
self.backend.storage_entries(block, storage_key, keys).await.map_err(Into::into) self.backend.storage_entries(block, storage_key, keys).map_err(Into::into)
} }
async fn storage_hash( fn storage_hash(
&self, &self,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
key: StorageKey, key: StorageKey,
block: Option<Block::Hash>, block: Option<Block::Hash>,
) -> RpcResult<Option<Block::Hash>> { ) -> RpcResult<Option<Block::Hash>> {
self.backend.storage_hash(block, storage_key, key).await.map_err(Into::into) self.backend.storage_hash(block, storage_key, key).map_err(Into::into)
} }
async fn storage_size( fn storage_size(
&self, &self,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
key: StorageKey, key: StorageKey,
block: Option<Block::Hash>, block: Option<Block::Hash>,
) -> RpcResult<Option<u64>> { ) -> RpcResult<Option<u64>> {
self.backend.storage_size(block, storage_key, key).await.map_err(Into::into) self.backend.storage_size(block, storage_key, key).map_err(Into::into)
} }
async fn read_child_proof( fn read_child_proof(
&self, &self,
child_storage_key: PrefixedStorageKey, child_storage_key: PrefixedStorageKey,
keys: Vec<StorageKey>, keys: Vec<StorageKey>,
@@ -497,7 +478,6 @@ where
) -> RpcResult<ReadProof<Block::Hash>> { ) -> RpcResult<ReadProof<Block::Hash>> {
self.backend self.backend
.read_child_proof(block, child_storage_key, keys) .read_child_proof(block, child_storage_key, keys)
.await
.map_err(Into::into) .map_err(Into::into)
} }
} }
+29 -34
View File
@@ -28,10 +28,7 @@ use super::{
use crate::SubscriptionTaskExecutor; use crate::SubscriptionTaskExecutor;
use futures::{future, stream, FutureExt, StreamExt}; use futures::{future, stream, FutureExt, StreamExt};
use jsonrpsee::{ use jsonrpsee::{core::Error as JsonRpseeError, PendingSubscription};
core::{async_trait, Error as JsonRpseeError},
PendingSubscription,
};
use sc_client_api::{ use sc_client_api::{
Backend, BlockBackend, BlockchainEvents, CallExecutor, ExecutorProvider, ProofProvider, Backend, BlockBackend, BlockchainEvents, CallExecutor, ExecutorProvider, ProofProvider,
StorageProvider, StorageProvider,
@@ -170,7 +167,6 @@ where
} }
} }
#[async_trait]
impl<BE, Block, Client> StateBackend<Block, Client> for FullState<BE, Block, Client> impl<BE, Block, Client> StateBackend<Block, Client> for FullState<BE, Block, Client>
where where
Block: BlockT + 'static, Block: BlockT + 'static,
@@ -190,7 +186,7 @@ where
+ 'static, + 'static,
Client::Api: Metadata<Block>, Client::Api: Metadata<Block>,
{ {
async fn call( fn call(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
method: String, method: String,
@@ -212,7 +208,7 @@ where
.map_err(client_err) .map_err(client_err)
} }
async fn storage_keys( fn storage_keys(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
prefix: StorageKey, prefix: StorageKey,
@@ -222,7 +218,7 @@ where
.map_err(client_err) .map_err(client_err)
} }
async fn storage_pairs( fn storage_pairs(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
prefix: StorageKey, prefix: StorageKey,
@@ -232,7 +228,7 @@ where
.map_err(client_err) .map_err(client_err)
} }
async fn storage_keys_paged( fn storage_keys_paged(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
prefix: Option<StorageKey>, prefix: Option<StorageKey>,
@@ -251,7 +247,7 @@ where
.map_err(client_err) .map_err(client_err)
} }
async fn storage( fn storage(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
key: StorageKey, key: StorageKey,
@@ -261,7 +257,7 @@ where
.map_err(client_err) .map_err(client_err)
} }
async fn storage_size( fn storage_size(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
key: StorageKey, key: StorageKey,
@@ -290,7 +286,7 @@ where
.map_err(client_err) .map_err(client_err)
} }
async fn storage_hash( fn storage_hash(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
key: StorageKey, key: StorageKey,
@@ -300,7 +296,7 @@ where
.map_err(client_err) .map_err(client_err)
} }
async fn metadata(&self, block: Option<Block::Hash>) -> std::result::Result<Bytes, Error> { fn metadata(&self, block: Option<Block::Hash>) -> std::result::Result<Bytes, Error> {
self.block_or_best(block).map_err(client_err).and_then(|block| { self.block_or_best(block).map_err(client_err).and_then(|block| {
self.client self.client
.runtime_api() .runtime_api()
@@ -310,7 +306,7 @@ where
}) })
} }
async fn runtime_version( fn runtime_version(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
) -> std::result::Result<RuntimeVersion, Error> { ) -> std::result::Result<RuntimeVersion, Error> {
@@ -321,7 +317,7 @@ where
}) })
} }
async fn query_storage( fn query_storage(
&self, &self,
from: Block::Hash, from: Block::Hash,
to: Option<Block::Hash>, to: Option<Block::Hash>,
@@ -337,16 +333,16 @@ where
call_fn() call_fn()
} }
async fn query_storage_at( fn query_storage_at(
&self, &self,
keys: Vec<StorageKey>, keys: Vec<StorageKey>,
at: Option<Block::Hash>, at: Option<Block::Hash>,
) -> std::result::Result<Vec<StorageChangeSet<Block::Hash>>, Error> { ) -> std::result::Result<Vec<StorageChangeSet<Block::Hash>>, Error> {
let at = at.unwrap_or_else(|| self.client.info().best_hash); let at = at.unwrap_or_else(|| self.client.info().best_hash);
self.query_storage(at, Some(at), keys).await self.query_storage(at, Some(at), keys)
} }
async fn read_proof( fn read_proof(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
keys: Vec<StorageKey>, keys: Vec<StorageKey>,
@@ -454,7 +450,7 @@ where
self.executor.spawn("substrate-rpc-subscription", Some("rpc"), fut.boxed()); self.executor.spawn("substrate-rpc-subscription", Some("rpc"), fut.boxed());
} }
async fn trace_block( fn trace_block(
&self, &self,
block: Block::Hash, block: Block::Hash,
targets: Option<String>, targets: Option<String>,
@@ -474,7 +470,6 @@ where
} }
} }
#[async_trait]
impl<BE, Block, Client> ChildStateBackend<Block, Client> for FullState<BE, Block, Client> impl<BE, Block, Client> ChildStateBackend<Block, Client> for FullState<BE, Block, Client>
where where
Block: BlockT + 'static, Block: BlockT + 'static,
@@ -493,7 +488,7 @@ where
+ 'static, + 'static,
Client::Api: Metadata<Block>, Client::Api: Metadata<Block>,
{ {
async fn read_child_proof( fn read_child_proof(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
@@ -518,7 +513,7 @@ where
.map_err(client_err) .map_err(client_err)
} }
async fn storage_keys( fn storage_keys(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
@@ -536,7 +531,7 @@ where
.map_err(client_err) .map_err(client_err)
} }
async fn storage_keys_paged( fn storage_keys_paged(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
@@ -562,7 +557,7 @@ where
.map_err(client_err) .map_err(client_err)
} }
async fn storage( fn storage(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
@@ -580,7 +575,7 @@ where
.map_err(client_err) .map_err(client_err)
} }
async fn storage_entries( fn storage_entries(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
@@ -595,18 +590,18 @@ where
}; };
let block = self.block_or_best(block).map_err(client_err)?; let block = self.block_or_best(block).map_err(client_err)?;
let client = self.client.clone(); let client = self.client.clone();
future::try_join_all(keys.into_iter().map(move |key| {
let res = client
.clone()
.child_storage(&BlockId::Hash(block), &child_info, &key)
.map_err(client_err);
async move { res } keys.into_iter()
})) .map(move |key| {
.await client
.clone()
.child_storage(&BlockId::Hash(block), &child_info, &key)
.map_err(client_err)
})
.collect()
} }
async fn storage_hash( fn storage_hash(
&self, &self,
block: Option<Block::Hash>, block: Option<Block::Hash>,
storage_key: PrefixedStorageKey, storage_key: PrefixedStorageKey,
+20 -40
View File
@@ -61,31 +61,23 @@ async fn should_return_storage() {
assert_eq!( assert_eq!(
client client
.storage(key.clone(), Some(genesis_hash).into()) .storage(key.clone(), Some(genesis_hash).into())
.await
.map(|x| x.map(|x| x.0.len())) .map(|x| x.map(|x| x.0.len()))
.unwrap() .unwrap()
.unwrap() as usize, .unwrap() as usize,
VALUE.len(), VALUE.len(),
); );
assert_matches!( assert_matches!(
client client.storage_hash(key.clone(), Some(genesis_hash).into()).map(|x| x.is_some()),
.storage_hash(key.clone(), Some(genesis_hash).into())
.await
.map(|x| x.is_some()),
Ok(true) Ok(true)
); );
assert_eq!(client.storage_size(key.clone(), None).unwrap().unwrap() as usize, VALUE.len(),);
assert_eq!( assert_eq!(
client.storage_size(key.clone(), None).await.unwrap().unwrap() as usize, client.storage_size(StorageKey(b":map".to_vec()), None).unwrap().unwrap() as usize,
VALUE.len(),
);
assert_eq!(
client.storage_size(StorageKey(b":map".to_vec()), None).await.unwrap().unwrap() as usize,
2 + 3, 2 + 3,
); );
assert_eq!( assert_eq!(
child child
.storage(prefixed_storage_key(), key, Some(genesis_hash).into()) .storage(prefixed_storage_key(), key, Some(genesis_hash).into())
.await
.map(|x| x.map(|x| x.0.len())) .map(|x| x.map(|x| x.0.len()))
.unwrap() .unwrap()
.unwrap() as usize, .unwrap() as usize,
@@ -114,7 +106,6 @@ async fn should_return_storage_entries() {
assert_eq!( assert_eq!(
child child
.storage_entries(prefixed_storage_key(), keys.to_vec(), Some(genesis_hash).into()) .storage_entries(prefixed_storage_key(), keys.to_vec(), Some(genesis_hash).into())
.await
.map(|x| x.into_iter().map(|x| x.map(|x| x.0.len()).unwrap()).sum::<usize>()) .map(|x| x.into_iter().map(|x| x.map(|x| x.0.len()).unwrap()).sum::<usize>())
.unwrap(), .unwrap(),
CHILD_VALUE1.len() + CHILD_VALUE2.len() CHILD_VALUE1.len() + CHILD_VALUE2.len()
@@ -126,7 +117,6 @@ async fn should_return_storage_entries() {
assert_matches!( assert_matches!(
child child
.storage_entries(prefixed_storage_key(), failing_keys, Some(genesis_hash).into()) .storage_entries(prefixed_storage_key(), failing_keys, Some(genesis_hash).into())
.await
.map(|x| x.iter().all(|x| x.is_some())), .map(|x| x.iter().all(|x| x.is_some())),
Ok(false) Ok(false)
); );
@@ -150,17 +140,16 @@ async fn should_return_child_storage() {
child_key.clone(), child_key.clone(),
key.clone(), key.clone(),
Some(genesis_hash).into(), Some(genesis_hash).into(),
).await, ),
Ok(Some(StorageData(ref d))) if d[0] == 42 && d.len() == 1 Ok(Some(StorageData(ref d))) if d[0] == 42 && d.len() == 1
); );
assert_matches!( assert_matches!(
child child
.storage_hash(child_key.clone(), key.clone(), Some(genesis_hash).into(),) .storage_hash(child_key.clone(), key.clone(), Some(genesis_hash).into(),)
.await
.map(|x| x.is_some()), .map(|x| x.is_some()),
Ok(true) Ok(true)
); );
assert_matches!(child.storage_size(child_key.clone(), key.clone(), None).await, Ok(Some(1))); assert_matches!(child.storage_size(child_key.clone(), key.clone(), None), Ok(Some(1)));
} }
#[tokio::test] #[tokio::test]
@@ -179,7 +168,6 @@ async fn should_return_child_storage_entries() {
let res = child let res = child
.storage_entries(child_key.clone(), keys.clone(), Some(genesis_hash).into()) .storage_entries(child_key.clone(), keys.clone(), Some(genesis_hash).into())
.await
.unwrap(); .unwrap();
assert_matches!( assert_matches!(
@@ -193,18 +181,12 @@ async fn should_return_child_storage_entries() {
if d[0] == 43 && d[1] == 44 && d.len() == 2 if d[0] == 43 && d[1] == 44 && d.len() == 2
); );
assert_matches!( assert_matches!(
executor::block_on(child.storage_hash( child
child_key.clone(), .storage_hash(child_key.clone(), keys[0].clone(), Some(genesis_hash).into())
keys[0].clone(), .map(|x| x.is_some()),
Some(genesis_hash).into()
))
.map(|x| x.is_some()),
Ok(true) Ok(true)
); );
assert_matches!( assert_matches!(child.storage_size(child_key.clone(), keys[0].clone(), None), Ok(Some(1)));
child.storage_size(child_key.clone(), keys[0].clone(), None).await,
Ok(Some(1))
);
} }
#[tokio::test] #[tokio::test]
@@ -216,9 +198,7 @@ async fn should_call_contract() {
use jsonrpsee::{core::Error, types::error::CallError}; use jsonrpsee::{core::Error, types::error::CallError};
assert_matches!( assert_matches!(
client client.call("balanceOf".into(), Bytes(vec![1, 2, 3]), Some(genesis_hash).into()),
.call("balanceOf".into(), Bytes(vec![1, 2, 3]), Some(genesis_hash).into())
.await,
Err(Error::Call(CallError::Failed(_))) Err(Error::Call(CallError::Failed(_)))
) )
} }
@@ -347,7 +327,7 @@ async fn should_query_storage() {
let keys = (1..6).map(|k| StorageKey(vec![k])).collect::<Vec<_>>(); let keys = (1..6).map(|k| StorageKey(vec![k])).collect::<Vec<_>>();
let result = api.query_storage(keys.clone(), genesis_hash, Some(block1_hash).into()); let result = api.query_storage(keys.clone(), genesis_hash, Some(block1_hash).into());
assert_eq!(result.await.unwrap(), expected); assert_eq!(result.unwrap(), expected);
// Query all changes // Query all changes
let result = api.query_storage(keys.clone(), genesis_hash, None.into()); let result = api.query_storage(keys.clone(), genesis_hash, None.into());
@@ -360,18 +340,18 @@ async fn should_query_storage() {
(StorageKey(vec![5]), Some(StorageData(vec![1]))), (StorageKey(vec![5]), Some(StorageData(vec![1]))),
], ],
}); });
assert_eq!(result.await.unwrap(), expected); assert_eq!(result.unwrap(), expected);
// Query changes up to block2. // Query changes up to block2.
let result = api.query_storage(keys.clone(), genesis_hash, Some(block2_hash)); let result = api.query_storage(keys.clone(), genesis_hash, Some(block2_hash));
assert_eq!(result.await.unwrap(), expected); assert_eq!(result.unwrap(), expected);
// Inverted range. // Inverted range.
let result = api.query_storage(keys.clone(), block1_hash, Some(genesis_hash)); let result = api.query_storage(keys.clone(), block1_hash, Some(genesis_hash));
assert_eq!( assert_eq!(
result.await.map_err(|e| e.to_string()), result.map_err(|e| e.to_string()),
Err(RpcError::Call(RpcCallError::Custom(ErrorObject::owned( Err(RpcError::Call(RpcCallError::Custom(ErrorObject::owned(
4001, 4001,
Error::InvalidBlockRange { Error::InvalidBlockRange {
@@ -392,7 +372,7 @@ async fn should_query_storage() {
let result = api.query_storage(keys.clone(), genesis_hash, Some(random_hash1)); let result = api.query_storage(keys.clone(), genesis_hash, Some(random_hash1));
assert_eq!( assert_eq!(
result.await.map_err(|e| e.to_string()), result.map_err(|e| e.to_string()),
Err(RpcError::Call(RpcCallError::Custom(ErrorObject::owned( Err(RpcError::Call(RpcCallError::Custom(ErrorObject::owned(
4001, 4001,
Error::InvalidBlockRange { Error::InvalidBlockRange {
@@ -413,7 +393,7 @@ async fn should_query_storage() {
let result = api.query_storage(keys.clone(), random_hash1, Some(genesis_hash)); let result = api.query_storage(keys.clone(), random_hash1, Some(genesis_hash));
assert_eq!( assert_eq!(
result.await.map_err(|e| e.to_string()), result.map_err(|e| e.to_string()),
Err(RpcError::Call(RpcCallError::Custom(ErrorObject::owned( Err(RpcError::Call(RpcCallError::Custom(ErrorObject::owned(
4001, 4001,
Error::InvalidBlockRange { Error::InvalidBlockRange {
@@ -434,7 +414,7 @@ async fn should_query_storage() {
let result = api.query_storage(keys.clone(), random_hash1, None); let result = api.query_storage(keys.clone(), random_hash1, None);
assert_eq!( assert_eq!(
result.await.map_err(|e| e.to_string()), result.map_err(|e| e.to_string()),
Err(RpcError::Call(RpcCallError::Custom(ErrorObject::owned( Err(RpcError::Call(RpcCallError::Custom(ErrorObject::owned(
4001, 4001,
Error::InvalidBlockRange { Error::InvalidBlockRange {
@@ -455,7 +435,7 @@ async fn should_query_storage() {
let result = api.query_storage(keys.clone(), random_hash1, Some(random_hash2)); let result = api.query_storage(keys.clone(), random_hash1, Some(random_hash2));
assert_eq!( assert_eq!(
result.await.map_err(|e| e.to_string()), result.map_err(|e| e.to_string()),
Err(RpcError::Call(RpcCallError::Custom(ErrorObject::owned( Err(RpcError::Call(RpcCallError::Custom(ErrorObject::owned(
4001, 4001,
Error::InvalidBlockRange { Error::InvalidBlockRange {
@@ -476,7 +456,7 @@ async fn should_query_storage() {
let result = api.query_storage_at(keys.clone(), Some(block1_hash)); let result = api.query_storage_at(keys.clone(), Some(block1_hash));
assert_eq!( assert_eq!(
result.await.unwrap(), result.unwrap(),
vec![StorageChangeSet { vec![StorageChangeSet {
block: block1_hash, block: block1_hash,
changes: vec![ changes: vec![
@@ -506,7 +486,7 @@ async fn should_return_runtime_version() {
[\"0xf78b278be53f454c\",2],[\"0xab3c0572291feb8b\",1],[\"0xbc9d89904f5b923f\",1]],\ [\"0xf78b278be53f454c\",2],[\"0xab3c0572291feb8b\",1],[\"0xbc9d89904f5b923f\",1]],\
\"transactionVersion\":1,\"stateVersion\":1}"; \"transactionVersion\":1,\"stateVersion\":1}";
let runtime_version = api.runtime_version(None.into()).await.unwrap(); let runtime_version = api.runtime_version(None.into()).unwrap();
let serialized = serde_json::to_string(&runtime_version).unwrap(); let serialized = serde_json::to_string(&runtime_version).unwrap();
assert_eq!(serialized, result); assert_eq!(serialized, result);