mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 00:31:02 +00:00
Define StorageDoubleMapKeyProvider
Signed-off-by: Serban Iorga <serban@parity.io>
This commit is contained in:
committed by
Bastian Köcher
parent
f9af3f2d6e
commit
cd36d1e15f
@@ -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,
|
||||
|
||||
@@ -25,10 +25,9 @@ use crate::{
|
||||
|
||||
use async_trait::async_trait;
|
||||
use bp_parachains::{
|
||||
best_parachain_head_hash_storage_key_at_target, imported_parachain_head_storage_key_at_target,
|
||||
BestParaHeadHash,
|
||||
best_parachain_head_hash_storage_key_at_target, BestParaHeadHash, ImportedParaHeadsKeyProvider,
|
||||
};
|
||||
use bp_polkadot_core::parachains::{ParaHash, ParaHead, ParaHeadsProof, ParaId};
|
||||
use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId};
|
||||
use bp_runtime::HeaderIdProvider;
|
||||
use codec::{Decode, Encode};
|
||||
use parachains_relay::{
|
||||
@@ -131,14 +130,14 @@ where
|
||||
let best_para_head_hash: Option<BestParaHeadHash> =
|
||||
self.client.storage_value(best_para_head_hash_key, Some(at_block.1)).await?;
|
||||
if let (Some(metrics), &Some(ref best_para_head_hash)) = (metrics, &best_para_head_hash) {
|
||||
let imported_para_head_key = imported_parachain_head_storage_key_at_target(
|
||||
P::SourceRelayChain::PARACHAINS_FINALITY_PALLET_NAME,
|
||||
para_id,
|
||||
best_para_head_hash.head_hash,
|
||||
);
|
||||
let imported_para_header = self
|
||||
let imported_para_head = self
|
||||
.client
|
||||
.storage_value::<ParaHead>(imported_para_head_key, Some(at_block.1))
|
||||
.storage_double_map_value::<ImportedParaHeadsKeyProvider>(
|
||||
P::SourceRelayChain::PARACHAINS_FINALITY_PALLET_NAME,
|
||||
¶_id,
|
||||
&best_para_head_hash.head_hash,
|
||||
Some(at_block.1),
|
||||
)
|
||||
.await?
|
||||
.and_then(|h| match HeaderOf::<P::SourceParachain>::decode(&mut &h.0[..]) {
|
||||
Ok(header) => Some(header),
|
||||
@@ -154,9 +153,9 @@ where
|
||||
None
|
||||
},
|
||||
});
|
||||
if let Some(imported_para_header) = imported_para_header {
|
||||
if let Some(imported_para_head) = imported_para_head {
|
||||
metrics
|
||||
.update_best_parachain_block_at_target(para_id, *imported_para_header.number());
|
||||
.update_best_parachain_block_at_target(para_id, *imported_para_head.number());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user