From 71bab3845a5071ee0f14d30a4be49adf7f79223a Mon Sep 17 00:00:00 2001 From: Keri Date: Fri, 29 Jan 2021 14:50:25 -0700 Subject: [PATCH] Add get_uncle_by_block, deprecate getUncleByBlock --- docs/overview.rst | 2 +- docs/web3.eth.rst | 10 +++++++--- web3/_utils/method_formatters.py | 2 +- web3/eth.py | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/overview.rst b/docs/overview.rst index 36113a3d9f..abf0ef5a49 100644 --- a/docs/overview.rst +++ b/docs/overview.rst @@ -149,7 +149,7 @@ API - :meth:`web3.eth.get_transaction() ` - :meth:`web3.eth.get_transaction_by_block() ` - :meth:`web3.eth.getTransactionCount() ` -- :meth:`web3.eth.getUncleByBlock() ` +- :meth:`web3.eth.get_uncle_by_block() ` - :meth:`web3.eth.getUncleCount() ` diff --git a/docs/web3.eth.rst b/docs/web3.eth.rst index e58c94b2a8..0e288974f6 100644 --- a/docs/web3.eth.rst +++ b/docs/web3.eth.rst @@ -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 @@ -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', @@ -500,6 +500,10 @@ The following methods are available on the ``web3.eth`` namespace. ... }) +.. 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) diff --git a/web3/_utils/method_formatters.py b/web3/_utils/method_formatters.py index c38373c346..df33e17879 100644 --- a/web3/_utils/method_formatters.py +++ b/web3/_utils/method_formatters.py @@ -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([ diff --git a/web3/eth.py b/web3/eth.py index 05f3377ad1..9399fafb34 100644 --- a/web3/eth.py +++ b/web3/eth.py @@ -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, @@ -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')