Add childstate_getStorageEntries RPC (#9459)

* Add storage query functions for multiple keys

fixes #9203

* Query all keys in one request and add more tests

* Make it compatible with stable release channel

* Update to new futures

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

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

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

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

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

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

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

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

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

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

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

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

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

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

* Satisfy borrowck

* Remove non-RPC `storage_entries` functions.

* Revert "Remove non-RPC `storage_entries` functions."

This reverts commit d840015c59ce865f879178594088c79082e8d151.

* Revert "Revert "Remove non-RPC `storage_entries` functions.""

This reverts commit 5813b439a4b467e022c627e3fe60cf2fa5520db4.

* Finally some formatting

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Falco Hirschenberger
2021-09-13 11:42:08 +02:00
committed by GitHub
parent 9245bfbbc2
commit c9197a2c6a
5 changed files with 210 additions and 1 deletions
+32 -1
View File
@@ -18,7 +18,11 @@
//! State API backend for full nodes.
use futures::{future, stream, FutureExt, SinkExt, StreamExt};
use futures::{
future,
future::{err, try_join_all},
stream, FutureExt, SinkExt, StreamExt,
};
use jsonrpc_pubsub::{manager::SubscriptionManager, typed::Subscriber, SubscriptionId};
use log::warn;
use rpc::Result as RpcResult;
@@ -715,6 +719,33 @@ where
async move { r }.boxed()
}
fn storage_entries(
&self,
block: Option<Block::Hash>,
storage_key: PrefixedStorageKey,
keys: Vec<StorageKey>,
) -> FutureResult<Vec<Option<StorageData>>> {
let child_info = match ChildType::from_prefixed_key(&storage_key) {
Some((ChildType::ParentKeyId, storage_key)) =>
Arc::new(ChildInfo::new_default(storage_key)),
None => return err(client_err(sp_blockchain::Error::InvalidChildStorageKey)).boxed(),
};
let block = match self.block_or_best(block) {
Ok(b) => b,
Err(e) => return err(client_err(e)).boxed(),
};
let client = self.client.clone();
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 }
}))
.boxed()
}
fn storage_hash(
&self,
block: Option<Block::Hash>,