ApeWorX / ApeWorX/web3.py

Add API to parse event data from generic filter

Open
#1,097 2 comments 1 reaction 0 assignees View on GitHub
priority: p3 nice to have
Dominant language
Python
Stars
5.5k
Forks
1.7k
Avg merge
3d 10h
Merged PRs (30d)
2

Description

### What was wrong?

> @theanht1 Hi guys, are there any ways to filter all events of a contract in a human readable way like contract.allEvents of web3js ?
> @carver not currently. Last we talked about it, the complexity of handling different events in response didn't seem worth the ease of setting up a single listener for all events. Better to set up a filter for each event you care about, and handle them distinctly.
> @theanht1 I want to handle events in the order of their created time, is multiple filters work in this case?

There isn't a great solution for this right now.

### How can it be fixed?

Maybe something like:

```py
my_contract = w3.eth.contract(...)
event_filter = web3.eth.filter({'address': my_contract.address})
for event_log in event_filter.get_all_events():
try:
parsed_event = my_contract.parse_unknown_event(event_log) # new API
except ValidationError:
# this is raised if the topic in event_log doesn't match any of events in the ABI
raise ValueError(f"{event_log} from {my_contract.address} filter not in {my_contract.events}")
else:
handle_parsed_event(parsed_event)

def handle_parsed_event():
# application-specific logic here
```

This is just a first stab at an API. I thought about putting it under `my_contract.events.parse_unknown()`, but then it would conflict with an event named `parse_unknown`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.