|
1 | | -from typing import Any, Callable, Dict, Generic |
| 1 | +from typing import Any, Callable, Dict, Generic, Tuple |
2 | 2 | from thirdweb.constants.events import EventType |
3 | 3 | from thirdweb.core.classes.contract_wrapper import ContractWrapper |
4 | 4 | from thirdweb.types.contract import TContractABI |
5 | | -from thirdweb.types.events import TxEvent |
6 | | - |
7 | | - |
| 5 | +from thirdweb.types.events import EventQueryOptions, TxEvent |
| 6 | +from web3.datastructures import AttributeDict |
8 | 7 | class ContractEvents(Generic[TContractABI]): |
9 | 8 | _contract_wrapper: ContractWrapper[TContractABI] |
10 | 9 |
|
@@ -71,3 +70,16 @@ def remove_all_listeners(self): |
71 | 70 | """ |
72 | 71 |
|
73 | 72 | self._contract_wrapper.remove_all_listeners() |
| 73 | + |
| 74 | + def get_events(self, event_name: str, options: EventQueryOptions = EventQueryOptions()) -> Tuple[AttributeDict]: |
| 75 | + """ |
| 76 | + Query past events of a specific type on the contract. |
| 77 | +
|
| 78 | + :param event_name: The name of the event to query. |
| 79 | + :param options: The options to use when querying for events, including block range specifications and filters |
| 80 | + :return: A list of events. |
| 81 | + """ |
| 82 | + |
| 83 | + events_interface = self._contract_wrapper.get_contract_interface().events[event_name] |
| 84 | + return events_interface.getLogs(options.filters, options.from_block, options.to_block) |
| 85 | + |
0 commit comments