-
Notifications
You must be signed in to change notification settings - Fork 268
Consolidate encoding and decoding methods, rename #161
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
Consolidate encoding and decoding methods, rename #161
Conversation
043b472
to
ed2e020
Compare
- Also add a breaking-change newsfragment for PR ethereum#161
4ec118b
to
98dddc6
Compare
- Also add a breaking-change newsfragment for PR ethereum#161
98dddc6
to
419fbd0
Compare
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.
Code looks really solid!
- I could take or leave the argument order change. It looks like we will need to update/make breaking changes in
web3.py
,eth-tester
, andeth-account
, and maybe others that I missed. Github isn't correctly picking up libraries that depend oneth-abi
for some reason. - I think the API would be a little bit nicer if we could pass arguments either with or without a list, for example, allowing:
encode(234, 'uint')
, but feel free to take or leave that feedback :)
We should also talk about whether or not we should do a beta release for these changes, but we can talk about that in our sync on Monday! 💥
Oh! I forgot to mention that we'll need to cut a v3 stable branch and deprecate the methods in that branch. So let's wait to merge this until I have a v3 stable branch out. I'll circle back and post a comment here once that's up! |
FWIW I'd say keeping the existing argument order makes some sense. I think the existing way works well if you think in terms of currying - the first argument is "more slowly" changing, the second argument "more quickly". Plus, and maybe this is more important, downstream users don't need to change. Trying to figure out what abi_encode("string", "(string)") encodes to will require less mental gymnastics, for instance. |
@charles-cooper thanks for the feedback. I could also take or leave it but figured we could consider it given we're already introducing breaking changes. It did feel like it made more sense to me reversed / the way it is in Solidity: "decode this data as these types". For better or worse I do think leaving the current argument order would cause less headaches and maybe we should just leave it alone. |
…better match Solidity" This reverts commit a2dbdeb. See conversation in PR ethereum#161 for reference.
…better match Solidity" This reverts commit a2dbdeb. See conversation in PR ethereum#161 for reference.
5fc87f9
to
7ea3ca0
Compare
…better match Solidity" This reverts commit a2dbdeb. See conversation in PR ethereum#161 for reference.
7ea3ca0
to
58dd3a4
Compare
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! The only thing that sticks out to me while looking over this again is: what happens if type_str
is passed without an array? Is the error clear enough or should we add our own? I was thinking about it in the context of people migrating from v2/v3 🤷
…`` / ``decode_abi``
…()`` - Update docs and rename ``encode_abi()`` to ``encode()`` and ``decode_abi()`` to ``decode()`` - Work TODOs from previous commit: turn ``encode_single()`` and ``decode_single()`` tests back on and refactor to use ``encode()`` / ``decode()``, respectively
- Also add a breaking-change newsfragment for PR ethereum#161
…better match Solidity" This reverts commit a2dbdeb. See conversation in PR ethereum#161 for reference.
58dd3a4
to
a282457
Compare
48cfde4
to
ecd5372
Compare
Updated with some better messaging and tests in this commit. Good thought. Could you do another pass through and let me know? |
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! 🚢
- Update eth-abi (methods changed name and some were deleted: ethereum/eth-abi#161) - Rename parity related Web3 methods/types - Rename some Web3 methods from camelcase to snakecase
- Update eth-abi (methods changed name and some were deleted: ethereum/eth-abi#161) - Rename parity related Web3 methods/types - Rename some Web3 methods from camelcase to snakecase
- Update eth-abi (methods changed name and some were deleted: ethereum/eth-abi#161) - Rename parity related Web3 methods/types - Rename some Web3 methods from camelcase to snakecase
What was wrong?
encode_single()
/decode_single()
andencode_abi()
/decode_abi()
have very similar functions. It has been suggested that these APIs be consolidated into one and the changes in this PR reflect keeping theencode_abi()
anddecode_abi()
functionality and renaming the methods toencode()
anddecode()
, respectively.encode_abi_packed()
has also been changed toencode_packed()
- as is Solidity's.I also changed, in a separate commit, the order in which the arguments are passed to these methods to be: values first; types second. This better mimics Solidity's abi methods for consistency and since these changes are breaking and significantly change the methods, this felt like a good time to make such a change. I'm also not tied to this idea and welcome any input if anyone feels strongly about not making this change.
Solidity
Python
closes #84
How was it fixed?
encode_single()
anddecode_single()
methods.encode_abi()
toencode()
anddecode_abi()
todecode()
.encode_single()
/decode_single()
tests to useencode()
anddecode()
with a single type passed in.To-Do
abi.decode(encoded_data, ('bytes32', 'bytes32'))
).Cute Animal Picture