chainHead: Add support for storage closest merkle descendant #14818 (#1153)

This PR adds support for fetching the closest merkle value of some key.


Builds on top of
- https://github.com/paritytech/trie/pull/199

Migrates https://github.com/paritytech/substrate/pull/14818 to the
monorepo.
Closes: https://github.com/paritytech/substrate/issues/14550
Closes: https://github.com/paritytech/polkadot-sdk/issues/1506

// @paritytech/subxt-team

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
This commit is contained in:
Alexandru Vasile
2023-09-18 13:54:44 +03:00
committed by GitHub
parent 20052e1675
commit 5d346643ca
15 changed files with 449 additions and 28 deletions
@@ -27,7 +27,7 @@ use crate::{
api::ChainHeadApiServer,
chain_head_follow::ChainHeadFollower,
error::Error as ChainHeadRpcError,
event::{FollowEvent, MethodResponse, OperationError, StorageQuery, StorageQueryType},
event::{FollowEvent, MethodResponse, OperationError, StorageQuery},
hex_string,
subscription::{SubscriptionManagement, SubscriptionManagementError},
},
@@ -329,19 +329,10 @@ where
let items = items
.into_iter()
.map(|query| {
if query.query_type == StorageQueryType::ClosestDescendantMerkleValue {
// Note: remove this once all types are implemented.
return Err(ChainHeadRpcError::InvalidParam(
"Storage query type not supported".into(),
))
}
Ok(StorageQuery {
key: StorageKey(parse_hex_param(query.key)?),
query_type: query.query_type,
})
let key = StorageKey(parse_hex_param(query.key)?);
Ok(StorageQuery { key, query_type: query.query_type })
})
.collect::<Result<Vec<_>, _>>()?;
.collect::<Result<Vec<_>, ChainHeadRpcError>>()?;
let child_trie = child_trie
.map(|child_trie| parse_hex_param(child_trie))