Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 1 addition & 82 deletions docs/contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,51 +282,6 @@ Each Contract Factory exposes the following methods.
``argument_filters``, optional. Expects a dictionary of argument names and values. When provided event logs are filtered for the event argument values. Event arguments can be both indexed or unindexed. Indexed values with be translated to their corresponding topic arguments. Unindexed arguments will be filtered using a regular expression.
``topics`` optional, accepts the standard JSON-RPC topics argument. See the JSON-RPC documentation for `eth_newFilter <https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newfilter>`_ more information on the ``topics`` parameters.

.. py:classmethod:: Contract.eventFilter(event_name, filter_params=None)

.. warning:: Contract.eventFilter() has been deprecated for :meth:`Contract.events.<event name>.createFilter()`

Creates a new :py:class:`web3.utils.filters.LogFilter` instance.

The ``event_name`` parameter should be the name of the contract event you
want to filter on.

If provided, ``filter_params`` should be a dictionary specifying
additional filters for log entries. The following keys are supported.

* ``filter``: ``dictionary`` - (optional) Dictionary keys should be
argument names for the Event arguments. Dictionary values should be the
value you want to filter on, or a list of values to be filtered on.
Lists of values will match log entries whose argument matches any value
in the list. Indexed and unindexed event arguments are accepted. The
processing of indexed argument values into hex encoded topics is handled
internally when using the ``filter`` parameter.
* ``fromBlock``: ``integer/tag`` - (optional, default: "latest") Integer
block number, or "latest" for the last mined block or "pending",
"earliest" for not yet mined transactions.
* ``toBlock``: ``integer/tag`` - (optional, default: "latest") Integer
block number, or "latest" for the last mined block or "pending",
"earliest" for not yet mined transactions.
* ``address``: ``string`` or list of ``strings``, each 20 Bytes -
(optional) Contract address or a list of addresses from which logs should
originate.
* ``topics``: list of 32 byte ``strings`` or ``null`` - (optional) Array of
topics that should be used for filtering, with the keccak hash of the event
signature as the first item, and the remaining items as hex encoded
argument values. Topics are order-dependent. This parameter can also be a
list of topic lists in which case filtering will match any of the provided
topic arrays. This argument is useful when relying on the internally
generated topic lists via the ``filter`` argument is not desired. If
``topics`` is included with the ``filter`` argument, the ``topics`` list
will be prepended to any topic lists inferred from the ``filter`` arguments.

The event topic for the event specified by ``event_name`` will be added to
the ``filter_params['topics']`` list.

If the :py:attr:`Contract.address` attribute for this contract is
non-null, the contract address will be added to the ``filter_params``.


.. py:classmethod:: Contract.deploy(transaction=None, args=None)

.. warning:: Deprecated: this method is deprecated in favor of
Expand Down Expand Up @@ -484,42 +439,6 @@ and the arguments are ambiguous.
1



.. _event-log-object:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slug is referenced elsewhere in the docs (via :ref:), which produces a warning.

Section below also referenced.


Event Log Object
~~~~~~~~~~~~~~~~

The Event Log Object is a python dictionary with the following keys:

* ``args``: Dictionary - The arguments coming from the event.
* ``event``: String - The event name.
* ``logIndex``: Number - integer of the log index position in the block.
* ``transactionIndex``: Number - integer of the transactions index position
log was created from.
* ``transactionHash``: String, 32 Bytes - hash of the transactions this log
was created from.
* ``address``: String, 32 Bytes - address from which this log originated.
* ``blockHash``: String, 32 Bytes - hash of the block where this log was
in. null when its pending.
* ``blockNumber``: Number - the block number where this log was in. null
when its pending.


.. code-block:: python

>>> transfer_filter = my_token_contract.eventFilter('Transfer', {'filter': {'_from': '0xdc3a9db694bcdd55ebae4a89b22ac6d12b3f0c24'}})
>>> transfer_filter.get_new_entries()
[...] # array of Event Log Objects that match the filter.

# wait a while...

>>> transfer_filter.get_new_entries()
[...] # new events since the last call

>>> transfer_filter.get_all_entries()
[...] # all events that match the filter.

Contract Functions
------------------

Expand Down Expand Up @@ -784,4 +703,4 @@ Utils
'_transactionData': b'',
'_debatingPeriod': 604800,
'_newCurator': True})


13 changes: 3 additions & 10 deletions tests/core/filtering/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,16 @@ def emitter_log_topics():
return LogTopics


def return_filter_by_api(
api_style=None,
def return_filter(
contract=None,
args=[]):
if api_style == 'v3':
with pytest.deprecated_call():
return contract.eventFilter(*args)
elif api_style == 'v4':
event_name = args[0]
kwargs = apply_key_map({'filter': 'argument_filters'}, args[1])
if 'fromBlock' not in kwargs:
kwargs['fromBlock'] = 'latest'
return contract.events[event_name].createFilter(**kwargs)
else:
raise ValueError("api_style must be 'v3 or v4'")


@pytest.fixture(params=['v3', 'v4'])
@pytest.fixture()
def create_filter(request):
return functools.partial(return_filter_by_api, request.param)
return functools.partial(return_filter)
34 changes: 0 additions & 34 deletions web3/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,40 +366,6 @@ def encodeABI(cls, fn_name, args=None, kwargs=None, data=None):

return encode_abi(cls.web3, fn_abi, fn_arguments, data)

@combomethod
@deprecated_for("contract.events.<event name>.createFilter")
def eventFilter(self, event_name, filter_params={}):
"""
Create filter object that tracks events emitted by this contract.
:param event_name: the name of the event to track
:param filter_params: other parameters to limit the events
"""
filter_meta_params = dict(filter_params)
argument_filters = filter_meta_params.pop('filter', {})

argument_filter_names = list(argument_filters.keys())
event_abi = self._find_matching_event_abi(
event_name,
argument_filter_names,
)

data_filter_set, event_filter_params = construct_event_filter_params(
event_abi,
contract_address=self.address,
argument_filters=argument_filters,
**filter_meta_params
)

log_data_extract_fn = functools.partial(get_event_data, event_abi)

log_filter = self.web3.eth.filter(event_filter_params)

log_filter.set_data_filters(data_filter_set)
log_filter.log_entry_formatter = log_data_extract_fn
log_filter.filter_params = event_filter_params

return log_filter

@combomethod
@deprecated_for("contract.functions.<method name>.estimateGas")
def estimateGas(self, transaction=None):
Expand Down