-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use scale-encode and scale-decode to encode and decode based on metadata #842
Conversation
…ws up in codegen)
…s since it's all specific to that
source: syn::Path, | ||
target: AbsolutePath, | ||
) -> Result<(), CodegenError> { | ||
let (key, val) = TypeSubstitutes::parse_path_substitution(source, target.0)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this fails only if the parsing fails.
Can't we throw a warning or something if insert
is ignored i.e, the given key already exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't bother only because this function is sortof dangling at the moment, but the point of it will be to override the RuntimeCall enum only if the user hasn't already overridden it via some type substitution of their own or whatever (which is necessary because we don't know where it lives at the point of setting up the default substitutions.. although maybe it could and I'll need to look into that).
Maybe it's best just to remove this function for now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome, looking forward to this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general looks fantastic, just a couple of comments/questions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a shame about losing the substituting of foreign types, but this inconvenience is massively outweighed by the overall improvement here: brilliant stuff 👊
Thank you :) I'm just writing a small followup PR which adds a small #[subxt::subxt(
runtime_metadata_path = "{}",
derive_for_all_types = "Eq, PartialEq",
substitute_type(
type = "sp_arithmetic::per_things::Perbill",
with = "Static<::sp_runtime::Perbill>"
)] And it'll at least provide a workaorund today (but of course having the proper impls will always be more robust, and this will leave a Static type you'll need to dig into) |
Part of a series:
This PR:
EncodeAsType
andDecodeAsType
on generated types (currently as well asEncode
andDecode
, but eventuallyEncode
/Decode
may become entirely optional as we use type information for all encoding and decoding). (derives stuff tweaked to allow attrs to also be added to types).EncodeAsType
andDecodeAsType
(well,IntoVisitor
/Visitor
) on custom types that need it.RootEvent
trait and codegen to assist in decoding (with type info) events into a Root event type.EncodeAsType
andDecodeAsType
(ie to encode and decode using type info). Note: Encoding StorageKeys still uses static encoding.RuntimeEvent
that's generated already (in part I did this because I wanted to be able to get hold of the path to theRuntimeCall
type, but for now I'm not trying to substitute it since there are other issues there.Breakage:
StorageClient
(ieapi.storage().address_root_bytes()
)What's the point of all this?
Previously, static things encoded/decoded to/from bytes based solely on their structure and not based on the actual type information. Dynamic
Value
types could be used in many places though, and those values would encode and decode based on type information.This PR takes steps towards unifying these approaches, and allows both static and dynamic values to be encoded in the same sort of way based on type information. This carries a couple of benefits:
Value
s when that robustness is needed, making static types strictly better.Call
enum for the "inner" call, but this enum is hardcoded to the pallet/call indexes of the node it was generated from. Now, everything is encoded dynamically (based on variant name in this case) across the board, so nested calls will "just work" across runtimes (and we can provide a nicer API for this too now).