decode_storage_value_current

Function decode_storage_value_current 

Source
pub fn decode_storage_value_current<'scale, 'resolver, T, V>(
    pallet_name: &str,
    storage_entry: &str,
    cursor: &mut &'scale [u8],
    metadata: &'resolver T,
    visitor: V,
) -> Result<V::Value<'scale, 'resolver>, StorageValueDecodeError<<<T as InfoAndResolver>::Info as StorageTypeInfo>::TypeId>>
where T: InfoAndResolver, T::Info: StorageTypeInfo, <<T as InfoAndResolver>::Info as StorageTypeInfo>::TypeId: Debug + Clone, T::Resolver: TypeResolver<TypeId = <<T as InfoAndResolver>::Info as StorageTypeInfo>::TypeId>, V: Visitor<TypeResolver = T::Resolver>, V::Error: Debug,
Expand description

Decode a storage value in a modern (V14-metadata-or-later) runtime.

ยงExample

Here, we decode some storage values from a block.

use frame_decode::storage::decode_storage_value_current;
use frame_decode::helpers::decode_with_visitor;
use frame_metadata::RuntimeMetadata;
use parity_scale_codec::Decode;
use scale_value::scale::ValueVisitor;

let metadata_bytes = std::fs::read("artifacts/metadata_10000000_9180.scale").unwrap();
let RuntimeMetadata::V14(metadata) = RuntimeMetadata::decode(&mut &*metadata_bytes).unwrap() else { return };

let storage_keyval_bytes = std::fs::read("artifacts/storage_10000000_9180_system_account.json").unwrap();
let storage_keyval_hex: Vec<(String, String)> = serde_json::from_slice(&storage_keyval_bytes).unwrap();

for (_key, val) in storage_keyval_hex {
    let value_bytes = hex::decode(val.trim_start_matches("0x")).unwrap();

    // Decode the storage value, here into a scale_value::Value:
    let account_value = decode_storage_value_current(
        "System",
        "Account",
        &mut &*value_bytes,
        &metadata,
        ValueVisitor::new()
    ).unwrap();
}