WIP new storage APIs

This commit is contained in:
James Wilson
2025-09-26 17:01:40 +01:00
parent 331c54063f
commit b720b59d95
3 changed files with 22 additions and 2 deletions
-1
View File
@@ -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;
+4
View File
@@ -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)]
+18 -1
View File
@@ -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<Target: IntoDecodableValues>(&self) -> Result<Target,StorageKeyError> {
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<Item = StorageKeyPart<'_, 'entry, 'atblock>> {