ApeWorX / ape

The smart contract development tool for Pythonistas, Data Scientists, and Security Professionals
https://apeworx.io
Apache License 2.0
870 stars 133 forks source link

Query: Event Searching, Polling, and Queries #448

Open fubuloubu opened 2 years ago

fubuloubu commented 2 years ago

Overview

Events currently don't do a whole lot: https://github.com/ApeWorX/ape/blob/main/src/ape/contracts/base.py#L221

One thing they should do is allow you to query past events and iterate over future ones:

These two features are implemented for blocks in the chain manager: https://github.com/ApeWorX/ape/blob/main/src/ape/contracts/base.py#L221 https://github.com/ApeWorX/ape/blob/main/src/ape/managers/chain.py#L127-L187

It would be nice to also have similar features for ape

Specification

my_contract.MyEvent[-1]  # Last `MyEvent` emitted by contract
iter(my_contract.MyEvent)  # Iterate overall events
my_contract.MyEvent.query(...)  # Similar to #380, #391, and #392
my_contract.MyEvent.poll_events(start_event=txn_hash)  # infinite iterator of new events (since `start_event`)
# NOTE: also add the `num_confirmations` kwarg here

Dependencies

Might be best to wait until after pydantic refactor.

fubuloubu commented 2 years ago

Note: the event query on our README doesn't work because of this :grimacing:

fubuloubu commented 1 year ago

I think this is all implemented