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

Handle ambiguous event names in contracts #3457

Closed
wants to merge 8 commits into from

Conversation

reedsa
Copy link
Contributor

@reedsa reedsa commented Aug 21, 2024

What was wrong?

Closes #964, #1704

The Contract class breaks down if a contract contains overloaded event names. BaseContractEvent._get_event_abi() calls eth-utils get_event_abi() but if any contract event shares the same name there is a problem with initialization of the Contract class.

Currently only the event name is used to filter ABI events from the contract ABI, so an exception is raised for "multiple events are found" when _get_event_abi is called on the Contract or ContractEvent class.

There are inconsistencies between Contract Functions and Events. The APIs should be the same for each so that there are methods to retrieve the ABI on the ContractFunction or ContractEvent. Exception messages can be shared across both and incorporate the same behaviors when a Function or Event cannot be matched with the ABI.

How was it fixed?

Add _get_abi methods to both BaseContractFunction and BaseContractEvent.

Modify get_abi_element to allow argument_names as an argument.

ContractEvent and ContractFunction initialized with an abi_element_identifier and abi. The abi_element_identifier stores the string signature representation of the event or function.

Also refactored _mismatched_abi_error_diagnosis so that messaging is clear for all ABI types, not just functions. MismatchedABI error messages are created based on the number of matches for specific filters. Error messages for MismatchedABI exceptions were using "encoding" terminology when the argument values were not encodable. Now that lookups can be made using the argument names and types (rather than values), the messages now state the arguments do not match the ABI.

Todo:

  • Clean up commit history
  • Add or update documentation related to these changes
  • Add entry to the release notes

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

reedsa added a commit to reedsa/web3.py that referenced this pull request Aug 22, 2024
@reedsa reedsa force-pushed the abi-event-arguments branch from 7a89c90 to 476fbba Compare August 22, 2024 17:28
reedsa added a commit to reedsa/web3.py that referenced this pull request Aug 22, 2024
@reedsa reedsa force-pushed the abi-event-arguments branch from 476fbba to 9ad25ff Compare August 22, 2024 17:43
reedsa added a commit to reedsa/web3.py that referenced this pull request Aug 22, 2024
@reedsa reedsa force-pushed the abi-event-arguments branch from 9ad25ff to a01afd8 Compare August 22, 2024 20:09
reedsa added a commit to reedsa/web3.py that referenced this pull request Aug 22, 2024
@reedsa reedsa force-pushed the abi-event-arguments branch from a01afd8 to f48fb1d Compare August 22, 2024 22:18
reedsa added a commit to reedsa/web3.py that referenced this pull request Aug 22, 2024
@reedsa reedsa force-pushed the abi-event-arguments branch from f48fb1d to 4e286b7 Compare August 22, 2024 22:46
@reedsa reedsa requested review from fselmo, pacrob and kclowes and removed request for fselmo, pacrob and kclowes August 23, 2024 16:29
reedsa added 5 commits August 28, 2024 09:52
New ``get_abi_element_by_name_and_type`` function to find unique ABIs based on argument names and types.
ContractEvent class method ``_get_abi_event()`` now allows passing argument names and types to match unique elements.
@reedsa reedsa force-pushed the abi-event-arguments branch from caa7fc8 to a274a8f Compare August 28, 2024 15:52
@reedsa reedsa closed this Sep 11, 2024
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.

Improve error messages on mismatched argument types
1 participant