How can I decode an extrinsic or event dynamically in rust? (I want to be able to decode across all parachains)
A lot of the heavy lifting seems to be frame-metadata
and scale-info
. There's a desub project that seems like it ought to be able to do this. I've managed to get a &Type<PortableForm>
based on the v14 metadata but I can't quite see how I can decode it (or alternatively decode it into a JsonValue).
Hmm will try this for extrinsics. Not sure on events?
OpaqueExtrinsic
isEncode
, so it's easy enough to get a byte slice. IIRC extrinsics are typically stored double-encoded (to avoid prescience of a chain's transaction format in lower-level code), so dpending on how desub works you may need to pass it an encoded byte slice. e.g. if you havext: OpaqueExtrinsic
, and you want a byte slice you would do either:&xt.encode()[..]
or&xt.encode().encode()[..]
.