|
83 | 83 | ABIFunctionNotFound,
|
84 | 84 | NoABIFound,
|
85 | 85 | NoABIFunctionsFound,
|
| 86 | + Web3ValidationError, |
86 | 87 | )
|
87 | 88 | from web3.types import (
|
88 | 89 | ABI,
|
|
91 | 92 | EventData,
|
92 | 93 | TxParams,
|
93 | 94 | )
|
| 95 | +from web3.utils import ( |
| 96 | + get_abi_input_names, |
| 97 | +) |
94 | 98 |
|
95 | 99 | if TYPE_CHECKING:
|
96 | 100 | from ens import AsyncENS # noqa: F401
|
@@ -156,25 +160,41 @@ async def get_logs(
|
156 | 160 |
|
157 | 161 | See also: :func:`web3.middleware.filter.local_filter_middleware`.
|
158 | 162 |
|
159 |
| - :param argument_filters: |
| 163 | + :param argument_filters: Filter by argument values. Indexed arguments are |
| 164 | + filtered by the node while non-indexed arguments are filtered by the library. |
160 | 165 | :param fromBlock: block number or "latest", defaults to "latest"
|
161 | 166 | :param toBlock: block number or "latest". Defaults to "latest"
|
162 |
| - :param blockHash: block hash. blockHash cannot be set at the |
| 167 | + :param block_hash: block hash. blockHash cannot be set at the |
163 | 168 | same time as fromBlock or toBlock
|
164 | 169 | :yield: Tuple of :class:`AttributeDict` instances
|
165 | 170 | """
|
166 |
| - abi = self._get_event_abi() |
| 171 | + event_abi = self._get_event_abi() |
| 172 | + |
| 173 | + # validate ``argument_filters`` if present |
| 174 | + if argument_filters is not None: |
| 175 | + event_arg_names = get_abi_input_names(event_abi) |
| 176 | + if not all(arg in event_arg_names for arg in argument_filters.keys()): |
| 177 | + raise Web3ValidationError( |
| 178 | + "When filtering by argument names, all argument names must be " |
| 179 | + "present in the contract's event ABI." |
| 180 | + ) |
| 181 | + |
167 | 182 | # Call JSON-RPC API
|
168 |
| - logs = await self.w3.eth.get_logs( |
169 |
| - self._get_event_filter_params( |
170 |
| - abi, argument_filters, fromBlock, toBlock, block_hash |
171 |
| - ) |
| 183 | + _filter_params = self._get_event_filter_params( |
| 184 | + event_abi, argument_filters, fromBlock, toBlock, block_hash |
172 | 185 | )
|
173 | 186 |
|
174 |
| - # Convert raw binary data to Python proxy objects as described by ABI |
175 |
| - return tuple( # type: ignore |
176 |
| - get_event_data(self.w3.codec, abi, entry) for entry in logs |
| 187 | + logs = await self.w3.eth.get_logs(_filter_params) |
| 188 | + # convert raw binary data to Python proxy objects as described by ABI: |
| 189 | + all_event_logs = tuple( |
| 190 | + get_event_data(self.w3.codec, event_abi, entry) for entry in logs |
| 191 | + ) |
| 192 | + filtered_logs = self._process_get_logs_argument_filters( |
| 193 | + event_abi, |
| 194 | + all_event_logs, |
| 195 | + argument_filters, |
177 | 196 | )
|
| 197 | + return cast(Awaitable[Iterable[EventData]], filtered_logs) |
178 | 198 |
|
179 | 199 | @combomethod
|
180 | 200 | async def create_filter(
|
|
0 commit comments