mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 13:31:10 +00:00
WIP new storage APIs
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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>> {
|
||||
|
||||
Reference in New Issue
Block a user