Skip to content

Commit ac0358a

Browse files
committed
Add documentation for event log error flags
1 parent ded9760 commit ac0358a

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

docs/contracts.rst

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,11 @@ For example:
717717
718718
:py:class:`ContractEvent` provides methods to interact with contract events. Positional and keyword arguments supplied to the contract event subclass will be used to find the contract event by signature.
719719

720-
.. py:method:: ContractEvents.myEvent(*args, **kwargs).processReceipt(transaction_receipt)
720+
.. py:method:: ContractEvents.myEvent(*args, **kwargs).processReceipt(transaction_receipt, errors=EventLogErrorFlag.strict)
721721
722722
Extracts the pertinent logs from a transaction receipt.
723723

724-
Returns a tuple of :ref:`Event Log Objects <event-log-object>`, emitted from the event (e.g. ``myEvent``),
724+
If there are no errors, ``processReceipt`` returns a tuple of :ref:`Event Log Objects <event-log-object>`, emitted from the event (e.g. ``myEvent``),
725725
with decoded ouput.
726726

727727
.. code-block:: python
@@ -732,6 +732,61 @@ For example:
732732
>>> rich_logs[0]['args']
733733
{'myArg': 12345}
734734
735+
By default, errors will be raised if the log doesn't match the provided ABI.
736+
However, errors can be optionally ignored by passing in the ``ignore`` or
737+
``discard`` flag located in the ``EventLogErrorFlags`` class. The ``discard``
738+
flag will discard any logs that raise an error during processing, and return
739+
the rest. The ``ignore`` flag will return the raw log that caused the error,
740+
without any processing, and will process any logs that do not raise an error.
741+
An ``EventLogErrorFlag`` is imported from web3/_utils/events.py.
742+
743+
.. code-block:: python
744+
745+
>>> from web3._utils.events import EventLogErrorFlags
746+
747+
>>> tx_hash = contract.functions.myFunction(12345).transact({'to':contract_address})
748+
>>> tx_receipt = w3.eth.getTransactionReceipt(tx_hash)
749+
>>> returned_logs = contract.events.myEvent().processReceipt(tx_receipt, errors=EventLogErrorFlags.ignore)
750+
>>> assert returned_logs[0] == tx_receipt['logs'][0]
751+
True
752+
>>> returned_logs = contract.events.myEvent().processReceipt(tx_receipt, errors=EventLogErrorFlags.discard)
753+
>>> assert returned_logs == ()
754+
True
755+
756+
757+
.. _event-log-object:
758+
759+
Event Log Object
760+
~~~~~~~~~~~~~~~~
761+
762+
The Event Log Object is a python dictionary with the following keys:
763+
764+
* ``args``: Dictionary - The arguments coming from the event.
765+
* ``event``: String - The event name.
766+
* ``logIndex``: Number - integer of the log index position in the block.
767+
* ``transactionIndex``: Number - integer of the transactions index position
768+
log was created from.
769+
* ``transactionHash``: String, 32 Bytes - hash of the transactions this log
770+
was created from.
771+
* ``address``: String, 32 Bytes - address from which this log originated.
772+
* ``blockHash``: String, 32 Bytes - hash of the block where this log was
773+
in. null when it's pending.
774+
* ``blockNumber``: Number - the block number where this log was in. null
775+
when it's pending.
776+
777+
778+
.. code-block:: python
779+
780+
>>> transfer_filter = my_token_contract.eventFilter('Transfer', {'filter': {'_from': '0xdc3a9db694bcdd55ebae4a89b22ac6d12b3f0c24'}})
781+
>>> transfer_filter.get_new_entries()
782+
[...] # array of Event Log Objects that match the filter.
783+
# wait a while...
784+
>>> transfer_filter.get_new_entries()
785+
[...] # new events since the last call
786+
>>> transfer_filter.get_all_entries()
787+
[...] # all events that match the filter.
788+
789+
735790
Utils
736791
-----
737792

0 commit comments

Comments
 (0)