Define StorageDoubleMapKeyProvider

Signed-off-by: Serban Iorga <serban@parity.io>
This commit is contained in:
Serban Iorga
2022-07-26 22:50:04 +03:00
committed by Bastian Köcher
parent f9af3f2d6e
commit cd36d1e15f
5 changed files with 100 additions and 65 deletions
+19 -1
View File
@@ -25,7 +25,7 @@ use crate::{
use async_std::sync::{Arc, Mutex};
use async_trait::async_trait;
use bp_runtime::HeaderIdProvider;
use bp_runtime::{HeaderIdProvider, StorageDoubleMapKeyProvider};
use codec::{Decode, Encode};
use frame_system::AccountInfo;
use futures::{SinkExt, StreamExt};
@@ -380,6 +380,24 @@ impl<C: Chain> Client<C> {
.transpose()
}
/// Read `DoubleMapStorage` value from runtime storage.
pub async fn storage_double_map_value<T: StorageDoubleMapKeyProvider>(
&self,
pallet_prefix: &str,
key1: &T::Key1,
key2: &T::Key2,
block_hash: Option<C::Hash>,
) -> Result<Option<T::Value>> {
let storage_key = T::final_key(pallet_prefix, key1, key2);
self.raw_storage_value(storage_key, block_hash)
.await?
.map(|encoded_value| {
T::Value::decode(&mut &encoded_value.0[..]).map_err(Error::ResponseParseFailed)
})
.transpose()
}
/// Read raw value from runtime storage.
pub async fn raw_storage_value(
&self,