Skip to content

Commit 684e61d

Browse files
committed
PR feedback
1 parent 76e8f0c commit 684e61d

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

docs/contracts.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ For example:
735735
By default, an error will be raised if the log doesn't match the provided ABI.
736736
However, errors can be optionally ignored by passing in the ``ignore`` or
737737
``discard`` flag located in the ``EventLogErrorFlags`` class. The ``discard``
738-
flag will discard any logs that raise an error during processing, and return
738+
flag will silently discard any logs that raise an error during processing, and return
739739
the rest. The ``ignore`` flag will return the raw log that caused the error,
740740
without any processing, and will process any logs that do not raise an error.
741741
An ``EventLogErrorFlag`` is imported from web3/_utils/events.py.

tests/core/contracts/test_extracting_event_data.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
)
66

77
from web3._utils.events import (
8-
EventLogErrorFlags,
8+
DISCARD,
9+
IGNORE,
10+
STRICT,
911
get_event_data,
1012
)
1113

@@ -271,7 +273,7 @@ def test_event_rich_log(
271273
@pytest.mark.parametrize(
272274
'errors',
273275
(
274-
(EventLogErrorFlags.strict),
276+
(STRICT),
275277
(),
276278
)
277279
)
@@ -298,8 +300,8 @@ def test_event_processing_with_strict_error_flag(
298300
@pytest.mark.parametrize(
299301
'errors,rich_log_length',
300302
(
301-
(EventLogErrorFlags.discard, 0),
302-
(EventLogErrorFlags.ignore, 1),
303+
(DISCARD, 0),
304+
(IGNORE, 1),
303305
)
304306
)
305307
def test_event_processing_with_caught_errors(
@@ -328,8 +330,10 @@ def test_event_processing_with_caught_errors(
328330
if len(returned_logs) == 0:
329331
assert returned_logs == ()
330332
elif len(returned_logs) == 1:
331-
returned_log = returned_logs[0]
333+
returned_log = dict(returned_logs[0])
332334

335+
assert repr(returned_log['errors']) == "ValueError('Expected 1 log topics. Got 0')"
336+
del returned_log['errors']
333337
assert returned_log == dup_txn_receipt['logs'][0]
334338
assert is_same_address(returned_log['address'], event_contract.address)
335339
else:

web3/_utils/events.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,11 @@ def _encode(self, value):
450450

451451

452452
class EventLogErrorFlags(Enum):
453-
strict = 'strict'
454-
ignore = 'ignore'
455-
discard = 'discard'
453+
STRICT = 'strict'
454+
IGNORE = 'ignore'
455+
DISCARD = 'discard'
456+
457+
458+
STRICT = EventLogErrorFlags.STRICT
459+
IGNORE = EventLogErrorFlags.IGNORE
460+
DISCARD = EventLogErrorFlags.DISCARD

web3/contract.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@
6262
to_hex,
6363
)
6464
from web3._utils.events import (
65+
DISCARD,
66+
IGNORE,
67+
STRICT,
6568
EventFilterBuilder,
66-
EventLogErrorFlags,
6769
get_event_data,
6870
is_dynamic_sized_type,
6971
)
@@ -82,6 +84,10 @@
8284
from web3._utils.transactions import (
8385
fill_transaction_defaults,
8486
)
87+
from web3.datastructures import (
88+
AttributeDict,
89+
MutableAttributeDict,
90+
)
8591
from web3.exceptions import (
8692
BadFunctionCallOutput,
8793
BlockNumberOutofRange,
@@ -984,24 +990,26 @@ def _get_event_abi(cls):
984990
event_name=cls.event_name)
985991

986992
@combomethod
987-
def processReceipt(self, txn_receipt, errors=EventLogErrorFlags.strict):
993+
def processReceipt(self, txn_receipt, errors=STRICT):
988994
return self._parse_logs(txn_receipt, errors)
989995

990996
@to_tuple
991997
def _parse_logs(self, txn_receipt, errors):
992998
for log in txn_receipt['logs']:
993999
try:
994-
decoded_log = get_event_data(self.abi, log)
1000+
rich_log = get_event_data(self.abi, log)
9951001
except MismatchedABI:
9961002
continue
9971003
except ValueError as e:
998-
if errors == EventLogErrorFlags.discard:
1004+
if errors == DISCARD:
9991005
continue
1000-
elif errors == EventLogErrorFlags.ignore:
1001-
decoded_log = log
1006+
elif errors == IGNORE:
1007+
new_log = MutableAttributeDict(log)
1008+
new_log["errors"] = e
1009+
rich_log = AttributeDict(new_log)
10021010
else:
10031011
raise e
1004-
yield decoded_log
1012+
yield rich_log
10051013

10061014
@combomethod
10071015
def createFilter(

0 commit comments

Comments
 (0)