paritytech / desub

Decode Substrate with Backwards-Compatible Metadata
GNU General Public License v3.0
39 stars 13 forks source link

feature request: decode events #85

Closed gilescope closed 2 years ago

gilescope commented 2 years ago

There's some prior art here: https://github.com/paritytech/cargo-contract/blob/2beb831163f8baa81c328a9cd46b1741f5470bbc/src/cmd/extrinsics/transcode/mod.rs#L194

but it would be great to be able to decode events in a non-strongly typed way.

gilescope commented 2 years ago

Turns out events are just another storage item so decode fine:

        let encoded_events = "0800000000000000000000000000000002000000010000000000109aa80700000000020000";
        let bin = hex::decode(encoded_events).unwrap();
        let storage = decoder::decode_storage(&metad);
        // system.events storage key:
        let key = "26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7";
        let storage_key = hex::decode(key).unwrap();
        let entry = storage.decode_key(&metad, &mut storage_key.as_slice()).expect("can decode storage");
        let val = decoder::decode_value_by_id(&metad, &entry.ty, &mut bin.as_slice()).unwrap();
gilescope commented 2 years ago

maybe this would be another great example though?