Module custom_values

Source
Expand description

Access custom values from metadata.

Use get to retrieve a custom value from some metadata, or validate to check that a static custom value address lines up with the value seen in the metadata.

§Example

use subxt_macro::subxt;
use subxt_core::custom_values;
use subxt_core::metadata;

// If we generate types without `subxt`, we need to point to `::subxt_core`:
#[subxt(
    crate = "::subxt_core",
    runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale",
)]
pub mod polkadot {}

// Some metadata we'd like to access custom values in:
let metadata_bytes = include_bytes!("../../../artifacts/polkadot_metadata_small.scale");
let metadata = metadata::decode_from(&metadata_bytes[..]).unwrap();

// At the moment, we don't expect to see any custom values in the metadata
// for Polkadot, so this will return an error:
let err = custom_values::get("Foo", &metadata);

Modules§

address
Construct addresses to access custom values with.

Functions§

get
Access a custom value by the address it is registered under. This can be just a str to get back a dynamic value, or a static address from the generated static interface to get a value of a static type returned.
get_bytes
Access the bytes of a custom value by the address it is registered under.
validate
Run the validation logic against some custom value address you’d like to access. Returns Ok(()) if the address is valid (or if it’s not possible to check since the address has no validation hash). Returns an error if the address was not valid (wrong name, type or raw bytes)