Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_uncle_by_block, deprecate getUncleByBlock #1862

Merged
merged 1 commit into from
Jan 29, 2021
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
2 changes: 1 addition & 1 deletion docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ API
- :meth:`web3.eth.get_transaction() <web3.eth.Eth.get_transaction>`
- :meth:`web3.eth.get_transaction_by_block() <web3.eth.Eth.get_transaction_by_block>`
- :meth:`web3.eth.getTransactionCount() <web3.eth.Eth.getTransactionCount>`
- :meth:`web3.eth.getUncleByBlock() <web3.eth.Eth.getUncleByBlock>`
- :meth:`web3.eth.get_uncle_by_block() <web3.eth.Eth.get_uncle_by_block>`
- :meth:`web3.eth.getUncleCount() <web3.eth.Eth.getUncleCount>`


Expand Down
12 changes: 8 additions & 4 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,10 @@ The following methods are available on the ``web3.eth`` namespace.
.. py:method:: Eth.getUncle(block_identifier)

.. note:: Method to get an Uncle from its hash is not available through
RPC, a possible substitute is the method ``Eth.getUncleByBlock``
RPC, a possible substitute is the method ``Eth.get_uncle_by_block``


.. py:method:: Eth.getUncleByBlock(block_identifier, uncle_index)
.. py:method:: Eth.get_uncle_by_block(block_identifier, uncle_index)

* Delegates to ``eth_getUncleByBlockHashAndIndex`` or
``eth_getUncleByBlockNumberAndIndex`` RPC methods
Expand All @@ -469,7 +469,7 @@ The following methods are available on the ``web3.eth`` namespace.

.. code-block:: python

>>> web3.eth.getUncleByBlock(56160, 0)
>>> web3.eth.get_uncle_by_block(56160, 0)
AttributeDict({
'author': '0xbe4532e1b1db5c913cf553be76180c1777055403',
'difficulty': '0x17dd9ca0afe',
Expand All @@ -495,11 +495,15 @@ The following methods are available on the ``web3.eth`` namespace.
})

# You can also refer to the block by hash:
>>> web3.eth.getUncleByBlock('0x685b2226cbf6e1f890211010aa192bf16f0a0cba9534264a033b023d7367b845', 0)
>>> web3.eth.get_uncle_by_block('0x685b2226cbf6e1f890211010aa192bf16f0a0cba9534264a033b023d7367b845', 0)
AttributeDict({
...
})

.. py:method:: Eth.getUncleByBlock(block_identifier, uncle_index)

.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.eth.Eth.get_uncle_by_block()`

.. py:method:: Eth.getUncleCount(block_identifier)

Expand Down
1 change: 1 addition & 0 deletions newsfragments/1862.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add get_uncle_by_block, deprecate getUncleByBlock
2 changes: 1 addition & 1 deletion web3/_utils/method_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def apply_list_to_array_formatter(formatter: Any) -> Callable[..., Any]:
apply_formatter_at_index(to_hex_if_integer, 0),
apply_formatter_at_index(to_hex_if_integer, 1),
),
RPC.eth_getUncleByBlockHashAndIndex: apply_formatter_at_index(integer_to_hex, 1),
RPC.eth_getUncleByBlockHashAndIndex: apply_formatter_at_index(to_hex_if_integer, 1),
RPC.eth_newFilter: apply_formatter_at_index(filter_params_formatter, 0),
RPC.eth_getLogs: apply_formatter_at_index(filter_params_formatter, 0),
RPC.eth_call: apply_formatters_to_sequence([
Expand Down
3 changes: 2 additions & 1 deletion web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def get_block_munger(
`eth_getUncleByBlockHashAndIndex`
`eth_getUncleByBlockNumberAndIndex`
"""
getUncleByBlock: Method[Callable[[BlockIdentifier, int], Uncle]] = Method(
get_uncle_by_block: Method[Callable[[BlockIdentifier, int], Uncle]] = Method(
method_choice_depends_on_args=select_method_for_block_identifier(
if_predefined=RPC.eth_getUncleByBlockNumberAndIndex,
if_hash=RPC.eth_getUncleByBlockHashAndIndex,
Expand Down Expand Up @@ -659,3 +659,4 @@ def setGasPriceStrategy(self, gas_price_strategy: GasPriceStrategy) -> None:
getTransactionByBlock = DeprecatedMethod(get_transaction_by_block,
'getTransactionByBlock',
'get_transaction_by_block')
getUncleByBlock = DeprecatedMethod(get_uncle_by_block, 'getUncleByBlock', 'get_uncle_by_block')