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

Move get_event_data and get_function_info from web3._utils modules to Public API #1596

Open
MikeHathaway opened this issue Mar 6, 2020 · 7 comments
Assignees

Comments

@MikeHathaway
Copy link

What was wrong?

Breaking changes were made to utility functions depended upon for client application functionality, making version updates more difficult.

How can it be fixed?

Python clients are using utility functions such as get_event_data and get_function_info extensively to interact with the blockchain. Given their utility to clients, these functions should be moved out of the _utils module and made public to ensure API stability across non-major releases.

@kclowes
Copy link
Collaborator

kclowes commented Mar 6, 2020

@MikeHathaway can you provide your use case for why you couldn't use contract.events.<your_event_name>.processLog or contract.events.<your event name>.processReceipt?

@cducrest
Copy link
Contributor

cducrest commented Sep 30, 2020

I encountered the same "problem". I receive a bunch of events from different contracts types at different addresses. I have a means to get the abi of the event from the log, and used to get the processed event with something like:

event = get_event_data(self._get_abi_for_log(raw_event_log), raw_event_log)

Since the way get_event_data works changed for me with upgrading web3, I now have to create a "contract" with only the event abi, which feels like a trick:

event_abi = self._get_abi_for_log(raw_event_log)
# The only public api to process the log is through the `contract` class, so we create one
contract_of_event = self._web3.eth.contract(
    address=raw_event_log["address"], abi=[event_abi]
)
events_of_contract = contract_of_event.events
event_of_log = getattr(events_of_contract, event_abi["name"])()

event = event_of_log.processLog(raw_event_log)

I agree that I could change this in my code by getting the contract and its abi instead of just the event abi upon receiving the log, but it seems unnecessary.

@kclowes kclowes mentioned this issue Sep 30, 2020
22 tasks
@kclowes
Copy link
Collaborator

kclowes commented Sep 30, 2020

Thanks for the code snippet @cducrest, that helps a lot! I don't see any reason why this wouldn't be able to go in the v6 release. Added to the v6 issue!

@pipermerriam
Copy link
Member

We can do this in the v5 line. This isn't a breaking change since it would just be exposing some previously private APIs as public.

@kclowes
Copy link
Collaborator

kclowes commented Sep 30, 2020

doh, true. Thanks @pipermerriam!

@reedsa
Copy link
Contributor

reedsa commented Feb 27, 2024

@kclowes @pacrob @fselmo this seems like a good fit for eth-utils inside a new contracts.py file. The utilities could be imported as:

from eth_utils import get_event_data, get_function_info

Any other ideas welcome! Let me know if this seems like a good approach.

@pacrob
Copy link
Contributor

pacrob commented Feb 28, 2024

I'd be more inclined to keep it in web3 and put it in web3/contract/utils.py. It requires more context (an eth-abi codec, the particular subset of the abi for the event, and the entry from a log) than the more generalizable functions from eth-utils normally do.

I don't have context for another use case, though, open to discuss.

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

Successfully merging a pull request may close this issue.

6 participants