Skip to content

Commit

Permalink
Camelcase keyword args
Browse files Browse the repository at this point in the history
  • Loading branch information
linda-le1 committed Dec 5, 2022
1 parent c85c1c7 commit db12062
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 103 deletions.
8 changes: 4 additions & 4 deletions docs/contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ Each Contract Factory exposes the following methods.
.. _contract_create_filter:

.. py:classmethod:: Contract.events.your_event_name.create_filter(from_block=block, to_block=block, \
.. py:classmethod:: Contract.events.your_event_name.create_filter(fromBlock=block, toBlock=block, \
argument_filters={"arg1": "value"}, topics=[])
Creates a new event filter, an instance of :py:class:`web3.utils.filters.LogFilter`.

- ``from_block`` is a mandatory field. Defines the starting block (exclusive) filter block range. It can be either the starting block number, or 'latest' for the last mined block, or 'pending' for unmined transactions. In the case of ``fromBlock``, 'latest' and 'pending' set the 'latest' or 'pending' block as a static value for the starting filter block.
- ``to_block`` optional. Defaults to 'latest'. Defines the ending block (inclusive) in the filter block range. Special values 'latest' and 'pending' set a dynamic range that always includes the 'latest' or 'pending' blocks for the filter's upper block range.
- ``fromBlock`` is a mandatory field. Defines the starting block (exclusive) filter block range. It can be either the starting block number, or 'latest' for the last mined block, or 'pending' for unmined transactions. In the case of ``fromBlock``, 'latest' and 'pending' set the 'latest' or 'pending' block as a static value for the starting filter block.
- ``toBlock`` optional. Defaults to 'latest'. Defines the ending block (inclusive) in the filter block range. Special values 'latest' and 'pending' set a dynamic range that always includes the 'latest' or 'pending' blocks for the filter's upper block range.
- ``address`` optional. Defaults to the contract address. The filter matches the event logs emanating from ``address``.
- ``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.
Expand Down Expand Up @@ -1066,7 +1066,7 @@ Event Log Object

.. doctest:: create_filter

>>> transfer_filter = my_token_contract.events.Transfer.create_filter(from_block="0x0", argument_filters={'from': '0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf'})
>>> transfer_filter = my_token_contract.events.Transfer.create_filter(fromBlock="0x0", argument_filters={'from': '0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf'})
>>> transfer_filter.get_new_entries()
[AttributeDict({'args': AttributeDict({'from': '0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf',
'to': '0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf',
Expand Down
4 changes: 2 additions & 2 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1205,8 +1205,8 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
codec,
address=argument_filters.get("address"),
argument_filters=argument_filters,
from_block=from_block,
to_block=to_block
fromBlock=from_block,
toBlock=to_block
)
logger.debug(f"Querying eth_getLogs with the following parameters: {event_filter_params}")
Expand Down
5 changes: 2 additions & 3 deletions docs/filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The :meth:`web3.eth.Eth.filter` method can be used to set up filters for:

.. code-block:: python
event_filter = mycontract.events.myEvent.create_filter(from_block='latest', argument_filters={'arg1':10})
event_filter = mycontract.events.myEvent.create_filter(fromBlock='latest', argument_filters={'arg1':10})
Or built manually by supplying `valid filter params <https://github.com/ethereum/execution-apis/blob/bea0266c42919a2fb3ee524fb91e624a23bc17c5/src/schemas/filter.json#L28>`_:

Expand All @@ -46,7 +46,6 @@ The :meth:`web3.eth.Eth.filter` method can be used to set up filters for:
Creating event filters requires that your Ethereum node has an API support enabled for filters.
Note that Infura support for filters does not offer access to `pending` filters.
To get event logs on other stateless nodes please see :class:`web3.contract.ContractEvents`.
Filter Class
Expand Down Expand Up @@ -134,7 +133,7 @@ creating event log filters. Refer to the following example:

.. code-block:: python
event_filter = myContract.events.<event_name>.create_filter(from_block="latest", argument_filters={'arg1':10})
event_filter = myContract.events.<event_name>.create_filter(fromBlock="latest", argument_filters={'arg1':10})
event_filter.get_new_entries()
See :meth:`web3.contract.Contract.events.your_event_name.create_filter()` documentation for more information.
Expand Down
2 changes: 1 addition & 1 deletion docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ a contract, you can leverage Web3.py filters.
>>> new_filter = web3.eth.filter('latest')
# Use case: filter for contract event "MyEvent"
>>> new_filter = deployed_contract.events.MyEvent.create_filter(from_block='latest')
>>> new_filter = deployed_contract.events.MyEvent.create_filter(fromBlock='latest')
# retrieve filter results:
>>> new_filter.get_all_entries()
Expand Down
2 changes: 1 addition & 1 deletion newsfragments/2709.breaking.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Snakecase the processReceipt, processLog, createFilter, and getLogs methods and createFilter keyword arguments
Snakecase the processReceipt, processLog, createFilter, and getLogs methods
12 changes: 6 additions & 6 deletions tests/core/contracts/test_contract_events_build_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ def test_build_filter_resetting_build_filter_properties(w3):
filter_builder = contract.events.Increased.build_filter()
# Address is setable from undeployed contract class
filter_builder.address = b"\x10" * 40
filter_builder.from_block = 0
filter_builder.to_block = "latest"
filter_builder.fromBlock = 0
filter_builder.toBlock = "latest"
# Test that all filter properties can only set values once
with pytest.raises(ValueError):
filter_builder.address = b"\x00" * 40
with pytest.raises(ValueError):
filter_builder.from_block = 1
filter_builder.fromBlock = 1
with pytest.raises(ValueError):
filter_builder.to_block = 50
filter_builder.toBlock = 50


def test_build_filter_argument_match_single_can_only_be_set_once(w3):
Expand All @@ -63,9 +63,9 @@ def test_deployed_build_filter_can_have_no_values_set(w3):
with pytest.raises(ValueError):
filter_builder.address = b"\x00" * 40
with pytest.raises(ValueError):
filter_builder.from_block = 1
filter_builder.fromBlock = 1
with pytest.raises(ValueError):
filter_builder.to_block = 50
filter_builder.toBlock = 50
with pytest.raises(ValueError):
filter_builder.args["value"].match_single(200)
with pytest.raises(ValueError):
Expand Down
2 changes: 1 addition & 1 deletion tests/core/contracts/test_extracting_event_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ def test_single_log_processing_with_errors(indexed_event_contract, dup_txn_recei


def test_get_all_entries_with_nested_tuple_event(w3, emitter):
struct_args_filter = emitter.events.LogStructArgs.create_filter(from_block=0)
struct_args_filter = emitter.events.LogStructArgs.create_filter(fromBlock=0)

tx_hash = emitter.functions.logStruct(1, (2, 3, (4,))).transact({"gas": 100000})
w3.eth.wait_for_transaction_receipt(tx_hash)
Expand Down
4 changes: 2 additions & 2 deletions tests/core/filtering/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ def emitter_log_topics():
def return_filter(contract=None, args=[]):
event_name = args[0]
kwargs = apply_key_map({"filter": "argument_filters"}, args[1])
if "from_block" not in kwargs:
kwargs["from_block"] = "latest"
if "fromBlock" not in kwargs:
kwargs["fromBlock"] = "latest"
return contract.events[event_name].create_filter(**kwargs)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_merged_topic_list_event(emitter):
]
with pytest.raises(TypeError):
emitter.events.LogTripleWithIndex().create_filter(
from_block="latest",
fromBlock="latest",
topics=manual_topics,
argument_filters={"arg0": 2222, "arg1": 2222, "arg2": 2222},
)
4 changes: 2 additions & 2 deletions tests/core/filtering/test_contract_on_event_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
@pytest.mark.parametrize("call_as_instance", (True, False))
def test_create_filter_address_parameter(emitter, Emitter, call_as_instance):
if call_as_instance:
event_filter = emitter.events.LogNoArguments.create_filter(from_block="latest")
event_filter = emitter.events.LogNoArguments.create_filter(fromBlock="latest")
else:
event_filter = Emitter.events.LogNoArguments.create_filter(from_block="latest")
event_filter = Emitter.events.LogNoArguments.create_filter(fromBlock="latest")

if call_as_instance:
# Assert this is a single string value, and not a list of addresses
Expand Down
4 changes: 2 additions & 2 deletions tests/core/filtering/test_contract_past_event_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_on_filter_using_get_all_entries_interface(
event_filter = builder.deploy(w3)
else:
event_filter = create_filter(
contract, ["LogNoArguments", {"from_block": "latest"}]
contract, ["LogNoArguments", {"fromBlock": "latest"}]
)

txn_hash = emitter.functions.logNoArgs(emitter_event_ids.LogNoArguments).transact()
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_get_all_entries_returned_block_data(
event_filter = builder.deploy(w3)
else:
event_filter = create_filter(
contract, ["LogNoArguments", {"from_block": txn_receipt["blockNumber"]}]
contract, ["LogNoArguments", {"fromBlock": txn_receipt["blockNumber"]}]
)

log_entries = event_filter.get_all_entries()
Expand Down
4 changes: 2 additions & 2 deletions tests/core/filtering/test_filters_against_many_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_event_filter_new_events(
event_filter = builder.deploy(w3)
else:
event_filter = emitter.events.LogNoArguments().create_filter(
from_block="latest"
fromBlock="latest"
)

expected_match_counter = 0
Expand Down Expand Up @@ -141,7 +141,7 @@ def gen_non_matching_transact():
event_filter = builder.deploy(w3)
else:
event_filter = emitter.events.LogNoArguments().create_filter(
from_block="latest"
fromBlock="latest"
)

expected_match_counter = 0
Expand Down
36 changes: 18 additions & 18 deletions web3/_utils/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ def is_indexed(arg: Any) -> bool:

class EventFilterBuilder:
formatter = None
_from_block = None
_to_block = None
_fromBlock = None
_toBlock = None
_address = None
_immutable = False

Expand All @@ -333,30 +333,30 @@ def __init__(
self._ordered_arg_names = tuple(arg["name"] for arg in event_abi["inputs"])

@property
def from_block(self) -> BlockIdentifier:
return self._from_block
def fromBlock(self) -> BlockIdentifier:
return self._fromBlock

@from_block.setter
def from_block(self, value: BlockIdentifier) -> None:
if self._from_block is None and not self._immutable:
self._from_block = value
@fromBlock.setter
def fromBlock(self, value: BlockIdentifier) -> None:
if self._fromBlock is None and not self._immutable:
self._fromBlock = value
else:
raise ValueError(
f"from_block is already set to {self._from_block!r}. "
f"fromBlock is already set to {self._fromBlock!r}. "
"Resetting filter parameters is not permitted"
)

@property
def to_block(self) -> BlockIdentifier:
return self._to_block
def toBlock(self) -> BlockIdentifier:
return self._toBlock

@to_block.setter
def to_block(self, value: BlockIdentifier) -> None:
if self._to_block is None and not self._immutable:
self._to_block = value
@toBlock.setter
def toBlock(self, value: BlockIdentifier) -> None:
if self._toBlock is None and not self._immutable:
self._toBlock = value
else:
raise ValueError(
f"to_block is already set to {self._to_block!r}. "
f"toBlock is already set to {self._toBlock!r}. "
"Resetting filter parameters is not permitted"
)

Expand Down Expand Up @@ -404,8 +404,8 @@ def data_argument_values(self) -> Tuple[Any, ...]:
def filter_params(self) -> FilterParams:
params = {
"topics": self.topics,
"from_block": self.from_block,
"to_block": self.to_block,
"fromBlock": self.fromBlock,
"toBlock": self.toBlock,
"address": self.address,
}
return valfilter(lambda x: x is not None, params)
Expand Down
12 changes: 6 additions & 6 deletions web3/_utils/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def construct_event_filter_params(
contract_address: Optional[ChecksumAddress] = None,
argument_filters: Optional[Dict[str, Any]] = None,
topics: Optional[Sequence[HexStr]] = None,
from_block: Optional[BlockIdentifier] = None,
to_block: Optional[BlockIdentifier] = None,
fromBlock: Optional[BlockIdentifier] = None,
toBlock: Optional[BlockIdentifier] = None,
address: Optional[ChecksumAddress] = None,
) -> Tuple[List[List[Optional[HexStr]]], FilterParams]:
filter_params: FilterParams = {}
Expand Down Expand Up @@ -115,11 +115,11 @@ def construct_event_filter_params(
else:
validate_address(filter_params["address"])

if from_block is not None:
filter_params["from_block"] = from_block
if fromBlock is not None:
filter_params["fromBlock"] = fromBlock

if to_block is not None:
filter_params["to_block"] = to_block
if toBlock is not None:
filter_params["toBlock"] = toBlock

data_filters_set = construct_event_data_set(event_abi, abi_codec, argument_filters)

Expand Down
Loading

0 comments on commit db12062

Please sign in to comment.