|
19 | 19 | from eth_typing import ChecksumAddress, HexStr |
20 | 20 | from web3 import AsyncWeb3, WebSocketProvider |
21 | 21 | from web3.contract import AsyncContract |
22 | | -from web3.exceptions import ProviderConnectionError, Web3RPCError |
| 22 | +from web3.exceptions import ProviderConnectionError, Web3RPCError, Web3ValueError |
23 | 23 | from web3.method import Method, default_root_munger |
24 | 24 | from web3.middleware import SignAndSendRawMiddlewareBuilder |
25 | 25 | from web3.types import LogReceipt, RPCEndpoint, TxParams, TxReceipt, Wei |
@@ -153,13 +153,13 @@ async def get_entity_metadata(self, entity_key: EntityKey) -> EntityMetadata: |
153 | 153 | string_annotations=list( |
154 | 154 | map( |
155 | 155 | lambda ann: Annotation(key=ann["key"], value=ann["value"]), |
156 | | - metadata.stringAnnotations, |
| 156 | + metadata.stringAnnotations or list(), |
157 | 157 | ) |
158 | 158 | ), |
159 | 159 | numeric_annotations=list( |
160 | 160 | map( |
161 | 161 | lambda ann: Annotation(key=ann["key"], value=ann["value"]), |
162 | | - metadata.numericAnnotations, |
| 162 | + metadata.numericAnnotations or list(), |
163 | 163 | ) |
164 | 164 | ), |
165 | 165 | ) |
@@ -367,18 +367,19 @@ async def log_handler( |
367 | 367 | logger.debug("New log: %s", log_receipt) |
368 | 368 | res = await self._process_arkiv_log_receipt(log_receipt) |
369 | 369 |
|
370 | | - if create_callback: |
371 | | - for create in res.creates: |
372 | | - create_callback(create) |
373 | | - if update_callback: |
374 | | - for update in res.updates: |
375 | | - update_callback(update) |
376 | | - if delete_callback: |
377 | | - for key in res.deletes: |
378 | | - delete_callback(key) |
379 | | - if extend_callback: |
380 | | - for extension in res.extensions: |
381 | | - extend_callback(extension) |
| 370 | + if res: |
| 371 | + if create_callback: |
| 372 | + for create in res.creates: |
| 373 | + create_callback(create) |
| 374 | + if update_callback: |
| 375 | + for update in res.updates: |
| 376 | + update_callback(update) |
| 377 | + if delete_callback: |
| 378 | + for key in res.deletes: |
| 379 | + delete_callback(key) |
| 380 | + if extend_callback: |
| 381 | + for extension in res.extensions: |
| 382 | + extend_callback(extension) |
382 | 383 |
|
383 | 384 | def create_subscription(topic: HexStr) -> LogsSubscription: |
384 | 385 | return LogsSubscription( |
@@ -442,15 +443,19 @@ def task_done(task: asyncio.Task[None]) -> None: |
442 | 443 | async def _process_arkiv_log_receipt( |
443 | 444 | self, |
444 | 445 | log_receipt: LogReceipt, |
445 | | - ) -> ArkivTransactionReceipt: |
| 446 | + ) -> ArkivTransactionReceipt | None: |
446 | 447 | # Read the first entry of the topics array, |
447 | 448 | # which is the hash of the event signature, identifying the event |
448 | 449 | topic = AsyncWeb3.to_hex(log_receipt["topics"][0]) |
449 | | - # Look up the corresponding event |
450 | | - # If there is no such event in the ABI, it probably needs to be added |
451 | | - event = self.arkiv_contract.get_event_by_topic(topic) |
452 | | - # Use the event to process the whole log |
453 | | - event_data = event.process_log(log_receipt) |
| 450 | + try: |
| 451 | + # Look up the corresponding event |
| 452 | + # If there is no such event in the ABI, it probably needs to be added |
| 453 | + event = self.arkiv_contract.get_event_by_topic(topic) |
| 454 | + |
| 455 | + # Use the event to process the whole log |
| 456 | + event_data = event.process_log(log_receipt) |
| 457 | + except Web3ValueError: |
| 458 | + return None |
454 | 459 |
|
455 | 460 | creates: list[CreateEntityReturnType] = [] |
456 | 461 | updates: list[UpdateEntityReturnType] = [] |
@@ -521,7 +526,9 @@ async def process_receipt( |
521 | 526 | receipt: TxReceipt, |
522 | 527 | ) -> AsyncGenerator[ArkivTransactionReceipt, None]: |
523 | 528 | for log in receipt["logs"]: |
524 | | - yield await self._process_arkiv_log_receipt(log) |
| 529 | + processed = await self._process_arkiv_log_receipt(log) |
| 530 | + if processed: |
| 531 | + yield processed |
525 | 532 |
|
526 | 533 | creates: list[CreateEntityReturnType] = [] |
527 | 534 | updates: list[UpdateEntityReturnType] = [] |
|
0 commit comments