1

It's possible to get the metadata information using the state_getMetadata RPC method. Then I want to reconstruct the corresponding rust types described in the metadata json type registry and decode the runtime state content based on the parsed type. Since the type registry has implemented JsonSchema, I tried to reconstruct using quicktype, but no luck. Any other ideas?

1 Answer 1

3

In Rust, it is not possible to create a struct at runtime due to the absence of a reflection system.

Currently, the most convenient approach is employed in subxt. It involves fetching the metadata first and constructing those types statically before embedding them into the compiling code.

For further reading on this topic, you may refer to:

1
  • I'd also just add that if you do want to be able to decode SCALE bytes (with a known type ID + metadata) at runtime, then github.com/paritytech/scale-value is useful; it's sortof the SCALE equivalent of serde_json::Value :)
    – jsdw
    Commented Sep 7, 2023 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.