diff --git a/core/src/blocks/extrinsics.rs b/core/src/blocks/extrinsics.rs index cda5cc1aac..39673bed03 100644 --- a/core/src/blocks/extrinsics.rs +++ b/core/src/blocks/extrinsics.rs @@ -11,7 +11,6 @@ use crate::{ }; use alloc::sync::Arc; use alloc::vec::Vec; -use core::ops::Deref; use frame_decode::extrinsics::Extrinsic; use scale_decode::DecodeAsType; use subxt_metadata::PalletMetadata; diff --git a/historic/src/error.rs b/historic/src/error.rs index ed49961d64..4c5dbd1e5a 100644 --- a/historic/src/error.rs +++ b/historic/src/error.rs @@ -295,6 +295,10 @@ pub enum StorageKeyError { index: usize, reason: scale_decode::Error, }, + #[error("Could not decode values out of the storage key: {reason}")] + DecodeKeyValueError { + reason: frame_decode::storage::StorageKeyValueDecodeError + } } #[allow(missing_docs)] diff --git a/historic/src/storage/storage_key.rs b/historic/src/storage/storage_key.rs index ad72f7f37c..1ec12e9202 100644 --- a/historic/src/storage/storage_key.rs +++ b/historic/src/storage/storage_key.rs @@ -3,7 +3,7 @@ use crate::{error::StorageKeyError, storage::storage_info::with_info}; use scale_info_legacy::{LookupName, TypeRegistrySet}; // This is part of our public interface. -pub use frame_decode::storage::StorageHasher; +pub use frame_decode::storage::{ StorageHasher, IntoDecodableValues }; enum AnyStorageKeyInfo<'atblock> { Legacy(StorageKeyInfo<'atblock, LookupName, TypeRegistrySet<'atblock>>), @@ -78,6 +78,23 @@ impl<'entry, 'atblock> StorageKey<'entry, 'atblock> { }) } + /// Attempt to decode the values contained within this storage key to the `Target` type + /// provided. This type is typically a tuple of types which each implement [`scale_decode::DecodeAsType`] + /// and correspond to each of the key types present, in order. + pub fn decode(&self) -> Result { + with_key_info!(info = &self.info => { + let values = frame_decode::storage::decode_storage_key_values( + self.bytes, + &info.info, + info.resolver + ).map_err(|e| { + StorageKeyError::DecodeKeyValueError { reason: e } + })?; + + Ok(values) + }) + } + /// Iterate over the parts of this storage key. Each part of a storage key corresponds to a /// single value that has been hashed. pub fn parts(&'_ self) -> impl ExactSizeIterator> {