Skip to content

Commit

Permalink
Snakecase getLogs
Browse files Browse the repository at this point in the history
  • Loading branch information
linda-le1 committed Dec 15, 2022
1 parent 0ec7a63 commit eb27a77
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 42 deletions.
4 changes: 2 additions & 2 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
"""
:param contract: Contract
:param events: List of web3 Event we scan
:param filters: Filters passed to getLogs
:param filters: Filters passed to get_logs
:param max_chunk_scan_size: JSON-RPC API limit in the number of blocks we query. (Recommendation: 10,000 for mainnet, 500,000 for testnets)
:param max_request_retries: How many times we try to reattempt a failed JSON-RPC call
:param request_retry_seconds: Delay between failed requests to let JSON-RPC server to recover
Expand Down Expand Up @@ -1180,7 +1180,7 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
"""
if from_block is None:
raise TypeError("Missing mandatory keyword argument to getLogs: fromBlock")
raise TypeError("Missing mandatory keyword argument to get_logs: from_block")
# Currently no way to poke this using a public Web3.py API.
# This will return raw underlying ABI JSON object for the event
Expand Down
2 changes: 1 addition & 1 deletion docs/filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Getting events without setting up a filter
You can query an Ethereum node for direct fetch of events, without creating a filter first.
This works on all node types.

For examples see :meth:`web3.contract.ContractEvents.getLogs`.
For examples see :meth:`web3.contract.ContractEvents.get_logs`.

Examples: Listening For Events
------------------------------
Expand Down
5 changes: 0 additions & 5 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1357,11 +1357,6 @@ with the filtering API.
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)
.. warning:: Deprecated: This property is deprecated in favor of
:attr:`~web3.eth.Eth.get_logs()`

.. py:method:: Eth.submit_hashrate(hashrate, nodeid)
* Delegates to ``eth_submitHashrate`` RPC Method
Expand Down
4 changes: 2 additions & 2 deletions tests/core/contracts/test_contract_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_updating_greeting_emits_event(w3, foo_contract):
receipt = w3.eth.wait_for_transaction_receipt(tx_hash, 180)

# get all of the `barred` logs for the contract
logs = foo_contract.events.barred.getLogs()
logs = foo_contract.events.barred.get_logs()
assert len(logs) == 1

# verify that the log's data matches the expected value
Expand Down Expand Up @@ -211,7 +211,7 @@ async def test_async_updating_greeting_emits_event(async_w3, async_foo_contract)
receipt = await async_w3.eth.wait_for_transaction_receipt(tx_hash, 180)

# get all of the `barred` logs for the contract
logs = await async_foo_contract.events.barred.getLogs()
logs = await async_foo_contract.events.barred.get_logs()
assert len(logs) == 1

# verify that the log's data matches the expected value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def test_contract_get_available_events(
assert len(events) == 19


def test_contract_getLogs_all(
def test_contract_get_logs_all(
w3,
emitter,
wait_for_transaction,
Expand All @@ -19,12 +19,12 @@ def test_contract_getLogs_all(
txn_hash = contract.functions.logNoArgs(event_id).transact()
wait_for_transaction(w3, txn_hash)

log_entries = list(contract.events.LogNoArguments.getLogs())
log_entries = list(contract.events.LogNoArguments.get_logs())
assert len(log_entries) == 1
assert log_entries[0]["transactionHash"] == txn_hash


def test_contract_getLogs_range(
def test_contract_get_logs_range(
w3,
emitter,
wait_for_transaction,
Expand All @@ -39,17 +39,21 @@ def test_contract_getLogs_range(
wait_for_transaction(w3, txn_hash)
assert w3.eth.block_number == 3

log_entries = list(contract.events.LogNoArguments.getLogs())
log_entries = list(contract.events.LogNoArguments.get_logs())
assert len(log_entries) == 1

log_entries = list(contract.events.LogNoArguments.getLogs(fromBlock=2, toBlock=3))
log_entries = list(
contract.events.LogNoArguments.get_logs(from_block=2, to_block=3)
)
assert len(log_entries) == 1

log_entries = list(contract.events.LogNoArguments.getLogs(fromBlock=1, toBlock=2))
log_entries = list(
contract.events.LogNoArguments.get_logs(from_block=1, to_block=2)
)
assert len(log_entries) == 0


def test_contract_getLogs_argument_filter(
def test_contract_get_logs_argument_filter(
w3, emitter, wait_for_transaction, emitter_event_ids
):

Expand All @@ -67,19 +71,19 @@ def test_contract_getLogs_argument_filter(
for txn_hash in txn_hashes:
wait_for_transaction(w3, txn_hash)

all_logs = contract.events.LogTripleWithIndex.getLogs(fromBlock=1)
all_logs = contract.events.LogTripleWithIndex.get_logs(from_block=1)
assert len(all_logs) == 4

# Filter all entries where arg1 in (1, 2)
partial_logs = contract.events.LogTripleWithIndex.getLogs(
fromBlock=1,
partial_logs = contract.events.LogTripleWithIndex.get_logs(
from_block=1,
argument_filters={"arg1": [1, 2]},
)
assert len(partial_logs) == 2

# Filter all entries where arg0 == 1
partial_logs = contract.events.LogTripleWithIndex.getLogs(
fromBlock=1,
partial_logs = contract.events.LogTripleWithIndex.get_logs(
from_block=1,
argument_filters={"arg0": 1},
)
assert len(partial_logs) == 4
40 changes: 20 additions & 20 deletions web3/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -1606,12 +1606,12 @@ def factory(cls, class_name: str, **kwargs: Any) -> PropertyCheckingFactory:

class ContractEvent(BaseContractEvent):
@combomethod
def getLogs(
def get_logs(
self,
argument_filters: Optional[Dict[str, Any]] = None,
fromBlock: Optional[BlockIdentifier] = None,
toBlock: Optional[BlockIdentifier] = None,
blockHash: Optional[HexBytes] = None,
from_block: Optional[BlockIdentifier] = None,
to_block: Optional[BlockIdentifier] = None,
block_hash: Optional[HexBytes] = None,
) -> Iterable[EventData]:
"""Get events for this contract instance using eth_getLogs API.
Expand All @@ -1632,7 +1632,7 @@ def getLogs(
from = max(mycontract.web3.eth.block_number - 10, 1)
to = mycontract.web3.eth.block_number
events = mycontract.events.Transfer.getLogs(fromBlock=from, toBlock=to)
events = mycontract.events.Transfer.get_logs(from_block=from, to_block=to)
for e in events:
print(e["args"]["from"],
Expand Down Expand Up @@ -1661,17 +1661,17 @@ def getLogs(
See also: :func:`web3.middleware.filter.local_filter_middleware`.
:param argument_filters:
:param fromBlock: block number or "latest", defaults to "latest"
:param toBlock: block number or "latest". Defaults to "latest"
:param blockHash: block hash. blockHash cannot be set at the
same time as fromBlock or toBlock
:param from_block: block number or "latest", defaults to "latest"
:param to_block: block number or "latest". Defaults to "latest"
:param block_hash: block hash. block_hash cannot be set at the
same time as from_block or to_block
:yield: Tuple of :class:`AttributeDict` instances
"""
abi = self._get_event_abi()
# Call JSON-RPC API
logs = self.w3.eth.get_logs(
self._get_event_filter_params(
abi, argument_filters, fromBlock, toBlock, blockHash
abi, argument_filters, from_block, to_block, block_hash
)
)

Expand All @@ -1681,12 +1681,12 @@ def getLogs(

class AsyncContractEvent(BaseContractEvent):
@combomethod
async def getLogs(
async def get_logs(
self,
argument_filters: Optional[Dict[str, Any]] = None,
fromBlock: Optional[BlockIdentifier] = None,
toBlock: Optional[BlockIdentifier] = None,
blockHash: Optional[HexBytes] = None,
from_block: Optional[BlockIdentifier] = None,
to_block: Optional[BlockIdentifier] = None,
block_hash: Optional[HexBytes] = None,
) -> Awaitable[Iterable[EventData]]:
"""Get events for this contract instance using eth_getLogs API.
Expand All @@ -1707,7 +1707,7 @@ async def getLogs(
from = max(mycontract.web3.eth.block_number - 10, 1)
to = mycontract.web3.eth.block_number
events = mycontract.events.Transfer.getLogs(fromBlock=from, toBlock=to)
events = mycontract.events.Transfer.get_logs(from_block=from, to_block=to)
for e in events:
print(e["args"]["from"],
Expand Down Expand Up @@ -1736,17 +1736,17 @@ async def getLogs(
See also: :func:`web3.middleware.filter.local_filter_middleware`.
:param argument_filters:
:param fromBlock: block number or "latest", defaults to "latest"
:param toBlock: block number or "latest". Defaults to "latest"
:param blockHash: block hash. blockHash cannot be set at the
same time as fromBlock or toBlock
:param from_block: block number or "latest", defaults to "latest"
:param to_block: block number or "latest". Defaults to "latest"
:param block_hash: block hash. block_hash cannot be set at the
same time as from_block or to_block
:yield: Tuple of :class:`AttributeDict` instances
"""
abi = self._get_event_abi()
# Call JSON-RPC API
logs = await self.w3.eth.get_logs(
self._get_event_filter_params(
abi, argument_filters, fromBlock, toBlock, blockHash # type: ignore
abi, argument_filters, from_block, to_block, block_hash # type: ignore
)
)

Expand Down

0 comments on commit eb27a77

Please sign in to comment.