frame-decode
Decode extrinsics, storage keys and storage values from modern or historic Substrate runtimes.
See https://docs.rs/frame-decode/latest/frame_decode/ for more documentation and examples.
Examples
Decoding historic extrinsics
use decode_extrinsic_legacy;
use RuntimeMetadata;
use Decode;
use ChainTypeRegistry;
use ValueVisitor;
let metadata_bytes = read.unwrap;
let V12 = decode.unwrap else ;
let extrinsics_bytes = read.unwrap;
let extrinsics_hex: = from_slice.unwrap;
// For historic types, we also need to provide type definitions, since they aren't in the
// metadata. We use scale-info-legacy to do this, and have already defined types for the
// Polkadot relay chain, so let's load those in:
let historic_type_bytes = read.unwrap;
let historic_types: ChainTypeRegistry = from_slice.unwrap;
// We configure the loaded types for the spec version of the extrinsics we want to decode,
// because types can vary between different spec versions.
let mut historic_types_for_spec = historic_types.for_spec_version;
// We also want to embelish these types with information from the metadata itself. This avoids
// needing to hardcode a load of type definitions that we can already construct from the metadata.
let types_from_metadata = type_registry_from_metadata.unwrap;
historic_types_for_spec.prepend;
for ext_hex in extrinsics_hex
Decoding historic storage keys
use decode_storage_key_legacy;
use RuntimeMetadata;
use Decode;
use ChainTypeRegistry;
use ValueVisitor;
let metadata_bytes = read.unwrap;
let V12 = decode.unwrap else ;
let storage_keyval_bytes = read.unwrap;
let storage_keyval_hex: = from_slice.unwrap;
// For historic types, we also need to provide type definitions, since they aren't in the
// metadata. We use scale-info-legacy to do this, and have already defined types for the
// Polkadot relay chain, so let's load those in:
let historic_type_bytes = read.unwrap;
let historic_types: ChainTypeRegistry = from_slice.unwrap;
// We configure the loaded types for the spec version of the extrinsics we want to decode,
// because types can vary between different spec versions.
let mut historic_types_for_spec = historic_types.for_spec_version;
// We also want to embelish these types with information from the metadata itself. This avoids
// needing to hardcode a load of type definitions that we can already construct from the metadata.
let types_from_metadata = type_registry_from_metadata.unwrap;
historic_types_for_spec.prepend;
for in storage_keyval_hex
Decoding historic storage values
use decode_storage_value_legacy;
use RuntimeMetadata;
use Decode;
use ChainTypeRegistry;
use ValueVisitor;
let metadata_bytes = read.unwrap;
let V12 = decode.unwrap else ;
let storage_keyval_bytes = read.unwrap;
let storage_keyval_hex: = from_slice.unwrap;
// For historic types, we also need to provide type definitions, since they aren't in the
// metadata. We use scale-info-legacy to do this, and have already defined types for the
// Polkadot relay chain, so let's load those in:
let historic_type_bytes = read.unwrap;
let historic_types: ChainTypeRegistry = from_slice.unwrap;
// We configure the loaded types for the spec version of the extrinsics we want to decode,
// because types can vary between different spec versions.
let mut historic_types_for_spec = historic_types.for_spec_version;
// We also want to embelish these types with information from the metadata itself. This avoids
// needing to hardcode a load of type definitions that we can already construct from the metadata.
let types_from_metadata = type_registry_from_metadata.unwrap;
historic_types_for_spec.prepend;
for in storage_keyval_hex