Skip to content
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

Utilities for Contract ABIs #271

Open
wants to merge 67 commits into
base: main
Choose a base branch
from
Open

Conversation

reedsa
Copy link
Contributor

@reedsa reedsa commented Apr 10, 2024

What was wrong?

Contract ABI utilities are useful for encoding and decoding contract transactions. Many utilities are implemented in web3.py as private methods.

Related to ethereum/web3.py#3036

These changes will be utilized in web3.py function/event utils:
ethereum/web3.py#3408
ethereum/web3.py#3401

How was it fixed?

Implements a public API for ABI utilities.

Todo:

  • Clean up commit history

  • Add or update documentation related to these changes

  • Add entry to the release notes

Cute Animal Picture

Screen Shot 2024-04-12 at 3 16 35 PM

eth_utils/abi.py Outdated Show resolved Hide resolved
eth_utils/abi.py Outdated Show resolved Hide resolved
Copy link
Contributor

@kclowes kclowes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new test functions, very nice! I didn't go through with a fine tooth comb, but looks good overall!

The only outstanding things I saw are:

  • the comment around which exceptions to raise, and where they live
  • I left a comment about raising vs returning an empty list. let me know what you think!

eth_utils/abi.py Outdated Show resolved Hide resolved
eth_utils/abi.py Outdated Show resolved Hide resolved
reedsa added a commit to reedsa/eth-utils that referenced this pull request Apr 12, 2024
eth_utils/encoding.py Outdated Show resolved Hide resolved
eth_utils/abi.py Outdated Show resolved Hide resolved
reedsa added a commit to reedsa/eth-utils that referenced this pull request Apr 15, 2024
reedsa added a commit to reedsa/eth-utils that referenced this pull request Apr 17, 2024
reedsa added a commit to reedsa/eth-utils that referenced this pull request Apr 18, 2024
reedsa added a commit to reedsa/eth-utils that referenced this pull request Apr 22, 2024
@reedsa reedsa marked this pull request as ready for review April 26, 2024 20:49
@reedsa reedsa requested review from pacrob and kclowes April 26, 2024 21:12
reedsa added a commit to reedsa/eth-utils that referenced this pull request Apr 29, 2024
@reedsa reedsa force-pushed the abi-element-utils branch 2 times, most recently from adfc679 to 854a6a5 Compare April 29, 2024 18:00
pyproject.toml Show resolved Hide resolved
eth_utils/abi.py Outdated Show resolved Hide resolved
eth_utils/abi.py Outdated Show resolved Hide resolved
@pacrob
Copy link
Contributor

pacrob commented May 1, 2024

Usage question - I pulled an ABI from web3 (extended_resolver.py), use get_all_function_abis to get function info, then take a name from that, say supportsInterface. From the description, I should be able to plug the abi and the function name into get_function_abi and get the same info back about that function, but I get:

MismatchedABI: 
Could not identify the intended function with name `supportsInterface`, positional arguments with type(s) `` and keyword arguments with type(s) `{}`.
Found 1 function(s) with the name `supportsInterface`: ['supportsInterface(bytes4)']
Function invocation failed due to improper number of arguments.

Same for get_function_info.

reedsa added a commit to reedsa/eth-utils that referenced this pull request Jun 5, 2024
reedsa added a commit to reedsa/eth-utils that referenced this pull request Jun 5, 2024
reedsa added a commit to reedsa/eth-utils that referenced this pull request Jun 5, 2024
@reedsa reedsa requested review from fselmo, kclowes and pacrob and removed request for fselmo, kclowes and pacrob June 5, 2024 21:44
setup.py Outdated Show resolved Hide resolved
eth_utils/abi.py Outdated Show resolved Hide resolved
eth_utils/abi.py Outdated Show resolved Hide resolved
Copy link
Contributor

@fselmo fselmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may look like a lot of comments but I left mostly nits, some things to discuss, and a few inconsistencies. The code looks great to me, most of it is around arg names, function names, deprecation cycle, and docstring blips.

eth_utils/abi.py Outdated Show resolved Hide resolved
eth_utils/abi.py Outdated Show resolved Hide resolved
eth_utils/abi.py Outdated Show resolved Hide resolved
eth_utils/abi.py Outdated Show resolved Hide resolved
eth_utils/abi.py Outdated Show resolved Hide resolved
eth_utils/abi.py Outdated Show resolved Hide resolved
eth_utils/abi.py Outdated Show resolved Hide resolved
eth_utils/abi.py Outdated Show resolved Hide resolved
eth_utils/abi.py Outdated Show resolved Hide resolved
eth_utils/abi.py Outdated Show resolved Hide resolved
``filter_abi_by_type`` was renamed from ``filter_by_type``.
``get_normalized_abi_arg_type`` is now called ``get_normalized_abi_component_type``.
Renamed ``_abi_inputs_types`` -> ``_abi_input_types``.
Updates argument names for utils, ``abi`` -> ``contract_abi``.
Docstring updates to match arguments and types accurately.
Also replaces ``Union[ABIFunction, ABIError, ABIFallback, ABIReceive]`` with ``ABICallable``.
@fselmo
Copy link
Contributor

fselmo commented Jun 17, 2024

I think all my concerns were addressed here. Will wait to approve once the eth-typing branch / version gets decided and updated rather than using the git commit hash for the branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants