Module events

Module events 

Source
Expand description

Decode and work with events.

§Example

use subxt_macro::subxt;
use subxt_core::config::PolkadotConfig;
use subxt_core::events;
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_full.scale",
)]
pub mod polkadot {}

// Some metadata we'll use to work with storage entries:
let metadata_bytes = include_bytes!("../../artifacts/polkadot_metadata_full.scale");
let metadata = metadata::decode_from(&metadata_bytes[..]).unwrap();

// Some bytes representing events (located in System.Events storage):
let event_bytes = hex::decode("1c00000000000000a2e9b53d5517020000000100000000000310c96d901d0102000000020000000408d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27dbeea5a030000000000000000000000000000020000000402d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48102700000000000000000000000000000000020000000407be5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25fbeea5a030000000000000000000000000000020000002100d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27dbeea5a03000000000000000000000000000000000000000000000000000000000000020000000000426df03e00000000").unwrap();

// We can decode these bytes like so:
let evs = events::decode_from::<PolkadotConfig>(event_bytes, metadata);

// And then do things like iterate over them and inspect details:
for ev in evs.iter() {
    let ev = ev.unwrap();
    println!("Index: {}", ev.index());
    println!("Name: {}.{}", ev.pallet_name(), ev.variant_name());
    println!("Fields: {:?}", ev.field_values().unwrap());
}

Structs§

EventDetails
The event details.
EventMetadataDetails
Details for the given event plucked from the metadata.
Events
A collection of events obtained from a block, bundled with the necessary information needed to decode and iterate over them.

Enums§

Phase
A phase of a block’s execution.

Traits§

StaticEvent
Trait to uniquely identify the events’s identity from the runtime metadata.

Functions§

decode_from
Create a new Events instance from the given bytes.