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