Skip to content

Commit

Permalink
Add get_filter_logs, deprecate getFilterLogs
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed Apr 2, 2021
1 parent 836996f commit 9611996
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Filter Class
Retrieve all entries for this filter.

Logs will be retrieved using the
:func:`web3.eth.Eth.getFilterLogs` which returns all entries that match the given
:func:`web3.eth.Eth.get_filter_logs` which returns all entries that match the given
filter.


Expand Down
2 changes: 1 addition & 1 deletion docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ API

- :meth:`web3.eth.filter() <web3.eth.Eth.filter>`
- :meth:`web3.eth.getFilterChanges() <web3.eth.Eth.getFilterChanges>`
- :meth:`web3.eth.getFilterLogs() <web3.eth.Eth.getFilterLogs>`
- :meth:`web3.eth.get_filter_logs() <web3.eth.Eth.get_filter_logs>`
- :meth:`web3.eth.uninstall_filter() <web3.eth.Eth.uninstall_filter>`
- :meth:`web3.eth.get_logs() <web3.eth.Eth.get_logs>`
- :meth:`Contract.events.your_event_name.createFilter() <web3.contract.Contract.events.your_event_name.createFilter>`
Expand Down
12 changes: 9 additions & 3 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ with the filtering API.
]
.. py:method:: Eth.getFilterLogs(self, filter_id)
.. py:method:: Eth.get_filter_logs(self, filter_id)
* Delegates to ``eth_getFilterLogs`` RPC Method.

Expand All @@ -1083,7 +1083,7 @@ with the filtering API.
.. code-block:: python
>>> filt = web3.eth.filter()
>>> web3.eth.getFilterLogs(filt.filter_id)
>>> web3.eth.get_filter_logs(filt.filter_id)
[
{
'address': '0xDc3A9Db694BCdd55EBaE4A89B22aC6D12b3F0c24',
Expand All @@ -1101,6 +1101,12 @@ with the filtering API.
]
.. py:method:: Eth.getFilterLogs(self, filter_id)
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.eth.Eth.get_filter_logs`


.. py:method:: Eth.uninstall_filter(self, filter_id)
* Delegates to ``eth_uninstallFilter`` RPC Method.
Expand All @@ -1125,7 +1131,7 @@ with the filtering API.
.. py:method:: Eth.get_logs(filter_params)
This is the equivalent of: creating a new
filter, running :meth:`~Eth.getFilterLogs`, and then uninstalling the filter. See
filter, running :meth:`~Eth.get_filter_logs`, and then uninstalling the filter. See
:meth:`~Eth.filter` for details on allowed filter parameters.

.. py:method:: Eth.getLogs(filter_params)
Expand Down
1 change: 1 addition & 0 deletions newsfragments/1919.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``eth.get_filter_logs``, deprecate ``eth.getFilterLogs``
2 changes: 1 addition & 1 deletion tests/core/middleware/test_filter_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_local_filter_middleware(w3, iter_block_number):
results = w3.eth.getFilterChanges(log_filter.filter_id)
assert results == FILTER_LOG

assert w3.eth.getFilterLogs(log_filter.filter_id) == FILTER_LOG
assert w3.eth.get_filter_logs(log_filter.filter_id) == FILTER_LOG

filter_ids = (
block_filter.filter_id,
Expand Down
2 changes: 1 addition & 1 deletion web3/_utils/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def get_new_entries(self) -> List[LogReceipt]:
return self._format_log_entries(log_entries)

def get_all_entries(self) -> List[LogReceipt]:
log_entries = self._filter_valid_entries(self.eth_module.getFilterLogs(self.filter_id))
log_entries = self._filter_valid_entries(self.eth_module.get_filter_logs(self.filter_id))
return self._format_log_entries(log_entries)

def _format_log_entries(self,
Expand Down
22 changes: 19 additions & 3 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,23 @@ def test_eth_newFilter(self, web3: "Web3") -> None:
assert is_list_like(changes)
assert not changes

logs = web3.eth.getFilterLogs(filter.filter_id)
logs = web3.eth.get_filter_logs(filter.filter_id)
assert is_list_like(logs)
assert not logs

result = web3.eth.uninstallFilter(filter.filter_id)
assert result is True

def test_eth_newFilter_deprecated(self, web3: "Web3") -> None:
filter = web3.eth.filter({})

changes = web3.eth.getFilterChanges(filter.filter_id)
assert is_list_like(changes)
assert not changes

with pytest.warns(DeprecationWarning,
match="getFilterLogs is deprecated in favor of get_filter_logs"):
logs = web3.eth.getFilterLogs(filter.filter_id)
assert is_list_like(logs)
assert not logs

Expand All @@ -1305,7 +1321,7 @@ def test_eth_newBlockFilter(self, web3: "Web3") -> None:
assert not changes

# TODO: figure out why this fails in go-ethereum
# logs = web3.eth.getFilterLogs(filter.filter_id)
# logs = web3.eth.get_filter_logs(filter.filter_id)
# assert is_list_like(logs)
# assert not logs

Expand All @@ -1321,7 +1337,7 @@ def test_eth_newPendingTransactionFilter(self, web3: "Web3") -> None:
assert not changes

# TODO: figure out why this fails in go-ethereum
# logs = web3.eth.getFilterLogs(filter.filter_id)
# logs = web3.eth.get_filter_logs(filter.filter_id)
# assert is_list_like(logs)
# assert not logs

Expand Down
3 changes: 2 additions & 1 deletion web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ def filter_munger(
mungers=[default_root_munger]
)

getFilterLogs: Method[Callable[[HexStr], List[LogReceipt]]] = Method(
get_filter_logs: Method[Callable[[HexStr], List[LogReceipt]]] = Method(
RPC.eth_getFilterLogs,
mungers=[default_root_munger]
)
Expand Down Expand Up @@ -700,3 +700,4 @@ def setGasPriceStrategy(self, gas_price_strategy: GasPriceStrategy) -> None:
'getTransactionReceipt',
'get_transaction_receipt')
uninstallFilter = DeprecatedMethod(uninstall_filter, 'uninstallFilter', 'uninstall_filter')
getFilterLogs = DeprecatedMethod(get_filter_logs, 'getFilterLogs', 'get_filter_logs')

0 comments on commit 9611996

Please sign in to comment.