-
Notifications
You must be signed in to change notification settings - Fork 263
Remove codec::Encode
and codec::Decode
derives from generated APIs by default
#2008
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
base: master
Are you sure you want to change the base?
Conversation
codec::Encode
and codec::Decode
from generated APIs by defaultcodec::Encode
and codec::Decode
derives from generated APIs by default
@@ -206,7 +206,7 @@ fn generate_storage_entry_fns( | |||
let key = &keys_slice[0]; | |||
if key.hasher.ends_with_key() { | |||
let arg = &key.arg_name; | |||
let keys = quote!(#static_storage_key::new(#arg.borrow())); | |||
let keys = quote!(#static_storage_key::new(#arg)); |
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.
We don't use references anymore because we need the self
of the key to work with EncodeAsType
and DecodeAsType
?
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.
The basic reason was just because previously we would SCALE encode the key before doing anything with it, but now we want to avoid SCALE encoding and so we keep the key itself, requiring us to have ownership of the key.
It might be that we can allow the stored key to be a reference as well or something like that, because we only need it for long enough to encode it given actual metadata!
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.
LGTM! 🙏
Most APIs in Subxt haven't used
codec::Encode
orcodec::Decode
in a while; these traits encode and decode bytes from/to a chain based on the precise shape of our generated types and don't take into account any changes in the chain metadata.One of the issues we recently hit was #2006, whereby
Encode
andDecode
derives in our generated APIs were not playing nicely with compact encoded generics.A solution is to migrate our generated APIs away from using
codec::Encode
orcodec::Decode
and relying only onEncodeAsType
andDecodeAstype
, which take the chain metadata into account and handle things like encoding and decoding compact encoded values transparently. This PR takes this path.As a nice side effect, the generated code size is reduced in line count by ~10%.
Users can still derive
Encode
andDecode
themselves on types that they want these traits on, or on everything, but all of the main Subxt interfaces no longer have any reliance on them, and so they do not need to be derviced by default.Closes #2006