Skip to content
Draft
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: 0 additions & 2 deletions docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ 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.get_transaction_count() <web3.eth.Eth.get_transaction_count>`
- :meth:`web3.eth.get_uncle_by_block() <web3.eth.Eth.get_uncle_by_block>`
- :meth:`web3.eth.get_uncle_count() <web3.eth.Eth.get_uncle_count>`


Sending Transactions
Expand Down
71 changes: 0 additions & 71 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -396,77 +396,6 @@ The following methods are available on the ``web3.eth`` namespace.
1


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

.. warning:: Deprecated. Will be removed in v8.

* Delegates to ``eth_getUncleByBlockHashAndIndex`` or
``eth_getUncleByBlockNumberAndIndex`` RPC methods

Returns the uncle at the index specified by ``uncle_index``
from the block specified by ``block_identifier``. Delegates to
``eth_getUncleByBlockNumberAndIndex`` if ``block_identifier`` is an
integer or one of the predefined block parameters ``'latest', 'earliest',
'pending'``, otherwise delegates to
``eth_getUncleByBlockHashAndIndex``. Throws ``BlockNotFound`` if the block is not found.

.. code-block:: python

>>> web3.eth.get_uncle_by_block(56160, 0)
AttributeDict({
'author': '0xbe4532e1b1db5c913cf553be76180c1777055403',
'difficulty': '0x17dd9ca0afe',
'extraData': '0x476574682f686261722f76312e302e312f6c696e75782f676f312e342e32',
'gasLimit': '0x2fefd8',
'gasUsed': '0x0',
'hash': '0xc78c35720d930f9ef34b4e6fb9d02ffec936f9b02a8f0fa858456e4afd4d5614',
'logsBloom':'0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'miner': '0xbe4532e1b1db5c913cf553be76180c1777055403',
'mixHash': '0x041e14603f35a82f6023802fec96ef760433292434a39787514f140950597e5e',
'nonce': '0x5d2b7e3f1af09995',
'number': '0xdb5e',
'parentHash': '0xcc30e8a9b15c548d5bf113c834143a8f0e1909fbfea96b2a208dc154293a78cf',
'receiptsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
'sealFields': ['0xa0041e14603f35a82f6023802fec96ef760433292434a39787514f140950597e5e', '0x885d2b7e3f1af09995'],
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
'size': None, 'stateRoot': '0x8ce2b1bf8e25a06a8ca34c647ff5fd0fa48ac725cc07f657ae1645ab8ef68c91',
'timestamp': '0x55c6a972',
'totalDifficulty': '0xce4c4f0a0b810b',
'transactions': [],
'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
'uncles': []
})

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


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

.. warning:: Deprecated. Will be removed in v8.

* Delegates to ``eth_getUncleCountByBlockHash`` or
``eth_getUncleCountByBlockNumber`` RPC methods

Returns the (integer) number of uncles associated with the block specified by ``block_identifier``.
Delegates to ``eth_getUncleCountByBlockNumber`` if ``block_identifier`` is an
integer or one of the predefined block parameters ``'latest', 'earliest',
'pending'``, otherwise delegates to ``eth_getUncleCountByBlockHash``.
Throws ``BlockNotFound`` if the block is not found.

.. code-block:: python

>>> web3.eth.get_uncle_count(56160)
1

# You can also refer to the block by hash:
>>> web3.eth.get_uncle_count('0x685b2226cbf6e1f890211010aa192bf16f0a0cba9534264a033b023d7367b845')
1


.. py:method:: Eth.get_transaction(transaction_hash)

* Delegates to ``eth_getTransactionByHash`` RPC Method
Expand Down
33 changes: 9 additions & 24 deletions tests/core/manager/test_response_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from web3._utils.method_formatters import (
raise_block_not_found,
raise_block_not_found_for_uncle_at_index,
raise_transaction_not_found,
)
from web3.exceptions import (
Expand Down Expand Up @@ -36,7 +35,11 @@
)


VALID_RESULT_OBJ_RESPONSE = {"jsonrpc": "2.0", "id": 1, "result": {"foo": "bar"}}
VALID_RESULT_OBJ_RESPONSE = {
"jsonrpc": "2.0",
"id": 1,
"result": {"foo": "bar"},
}
VALID_RESPONSE_EXTRA_FIELDS = merge(VALID_RESULT_OBJ_RESPONSE, {"unexpected": "field"})
VALID_RESPONSE_STRING_ID = merge(VALID_RESULT_OBJ_RESPONSE, {"id": "1"})

Expand Down Expand Up @@ -319,27 +322,6 @@ def test_formatted_response_error_responses_with_formatters_raise_expected_excep
BlockNotFound,
"Block with id: '0x03' not found.",
),
(
(),
# test raise_block_not_found_for_uncle_at_index
raise_block_not_found_for_uncle_at_index,
BlockNotFound,
"Unknown block identifier or uncle index",
),
(
("0x01",), # test handles missing param
# test raise_block_not_found_for_uncle_at_index
raise_block_not_found_for_uncle_at_index,
BlockNotFound,
"Unknown block identifier or uncle index",
),
(
("0x01", "0x00"), # both params
# test raise_block_not_found_for_uncle_at_index
raise_block_not_found_for_uncle_at_index,
BlockNotFound,
"Uncle at index: 0 of block with id: '0x01' not found.",
),
(
(),
# test raise_transaction_not_found
Expand All @@ -362,7 +344,10 @@ def test_formatted_response_null_and_0x_results_with_formatters(
with pytest.raises(error, match=re.escape(error_message)):
# test null result response
w3.manager.formatted_response(
VALID_RESPONSE_NULL_RESULT, params, identity, null_result_formatters
VALID_RESPONSE_NULL_RESULT,
params,
identity,
null_result_formatters,
)

with pytest.raises(error, match=re.escape(error_message)):
Expand Down
7 changes: 2 additions & 5 deletions web3/_utils/caching/caching_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ def is_cacheable_request(
RPC.eth_getBlockByNumber,
RPC.eth_getRawTransactionByBlockNumberAndIndex,
RPC.eth_getBlockTransactionCountByNumber,
RPC.eth_getUncleByBlockNumberAndIndex,
RPC.eth_getUncleCountByBlockNumber,
}
BLOCK_IN_RESULT = {
RPC.eth_getBlockByHash,
Expand All @@ -167,8 +165,6 @@ def is_cacheable_request(
}
BLOCKHASH_IN_PARAMS = {
RPC.eth_getRawTransactionByBlockHashAndIndex,
RPC.eth_getUncleByBlockHashAndIndex,
RPC.eth_getUncleCountByBlockHash,
}

INTERNAL_VALIDATION_MAP: dict[
Expand Down Expand Up @@ -336,7 +332,8 @@ async def _async_should_cache_response(

def async_handle_request_caching(
func: Callable[
[ASYNC_PROVIDER_TYPE, RPCEndpoint, Any], Coroutine[Any, Any, "RPCResponse"]
[ASYNC_PROVIDER_TYPE, RPCEndpoint, Any],
Coroutine[Any, Any, "RPCResponse"],
],
) -> Callable[..., Coroutine[Any, Any, "RPCResponse"]]:
async def wrapper(
Expand Down
50 changes: 17 additions & 33 deletions web3/_utils/method_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,10 @@ def storage_key_to_hexstr(value: bytes | int | str) -> HexStr:
is_array_of_dicts,
apply_list_to_array_formatter(transaction_result_formatter),
),
(is_array_of_strings, apply_list_to_array_formatter(to_hexbytes(32))),
(
is_array_of_strings,
apply_list_to_array_formatter(to_hexbytes(32)),
),
)
),
"transactionsRoot": apply_formatter_if(is_not_null, to_hexbytes(32)),
Expand Down Expand Up @@ -492,7 +495,10 @@ def storage_key_to_hexstr(value: bytes | int | str) -> HexStr:

filter_result_formatter = apply_one_of_formatters(
(
(is_array_of_dicts, apply_list_to_array_formatter(log_entry_formatter)),
(
is_array_of_dicts,
apply_list_to_array_formatter(log_entry_formatter),
),
(is_array_of_strings, apply_list_to_array_formatter(to_hexbytes(32))),
)
)
Expand Down Expand Up @@ -716,12 +722,6 @@ def storage_key_to_hexstr(value: bytes | int | str) -> HexStr:
RPC.eth_getRawTransactionByBlockHashAndIndex: apply_formatter_at_index(
to_hex_if_integer, 1
),
RPC.eth_getUncleCountByBlockNumber: apply_formatter_at_index(to_hex_if_integer, 0),
RPC.eth_getUncleByBlockNumberAndIndex: compose(
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(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_one_of_formatters(
Expand Down Expand Up @@ -953,7 +953,9 @@ def subscription_formatter(value: Any) -> HexBytes | HexStr | dict[str, Any]:
result_formatter = log_entry_formatter

elif either_set_is_a_subset(
result_key_set, set(TRANSACTION_RESULT_FORMATTERS.keys()), percentage=75
result_key_set,
set(TRANSACTION_RESULT_FORMATTERS.keys()),
percentage=75,
):
# newPendingTransactions, full transactions
result_formatter = transaction_result_formatter
Expand Down Expand Up @@ -1021,8 +1023,6 @@ def subscription_formatter(value: Any) -> HexBytes | HexStr | dict[str, Any]:
is_not_null,
receipt_formatter,
),
RPC.eth_getUncleCountByBlockHash: to_integer_if_hex,
RPC.eth_getUncleCountByBlockNumber: to_integer_if_hex,
RPC.eth_protocolVersion: compose(
apply_formatter_if(is_0x_prefixed, to_integer_if_hex),
apply_formatter_if(is_integer, str),
Expand Down Expand Up @@ -1102,7 +1102,9 @@ def combine_formatters(
yield formatter_map[method_name]


def get_request_formatters(method_name: RPCEndpoint) -> Callable[[RPCResponse], Any]:
def get_request_formatters(
method_name: RPCEndpoint,
) -> Callable[[RPCResponse], Any]:
request_formatter_maps = (
ABI_REQUEST_FORMATTERS,
# METHOD_NORMALIZERS needs to be after ABI_REQUEST_FORMATTERS
Expand All @@ -1126,22 +1128,6 @@ def raise_block_not_found(params: tuple[BlockIdentifier, bool]) -> NoReturn:
raise BlockNotFound(message)


def raise_block_not_found_for_uncle_at_index(
params: tuple[BlockIdentifier, HexStr | int],
) -> NoReturn:
try:
block_identifier = params[0]
uncle_index = to_integer_if_hex(params[1])
message = (
f"Uncle at index: {uncle_index} of block with id: "
f"{block_identifier!r} not found."
)
except IndexError:
message = "Unknown block identifier or uncle index"

raise BlockNotFound(message)


def raise_transaction_not_found(params: tuple[_Hash32]) -> NoReturn:
try:
transaction_hash = params[0]
Expand Down Expand Up @@ -1174,10 +1160,6 @@ def raise_transaction_not_found_with_index(
RPC.eth_getBlockReceipts: raise_block_not_found,
RPC.eth_getBlockTransactionCountByHash: raise_block_not_found,
RPC.eth_getBlockTransactionCountByNumber: raise_block_not_found,
RPC.eth_getUncleCountByBlockHash: raise_block_not_found,
RPC.eth_getUncleCountByBlockNumber: raise_block_not_found,
RPC.eth_getUncleByBlockHashAndIndex: raise_block_not_found_for_uncle_at_index,
RPC.eth_getUncleByBlockNumberAndIndex: raise_block_not_found_for_uncle_at_index,
RPC.eth_getTransactionByHash: raise_transaction_not_found,
RPC.eth_getTransactionByBlockHashAndIndex: raise_transaction_not_found_with_index,
RPC.eth_getTransactionByBlockNumberAndIndex: raise_transaction_not_found_with_index,
Expand Down Expand Up @@ -1256,7 +1238,9 @@ def get_result_formatters(
return compose(*partial_formatters, *formatters)


def get_error_formatters(method_name: RPCEndpoint) -> Callable[[RPCResponse], Any]:
def get_error_formatters(
method_name: RPCEndpoint,
) -> Callable[[RPCResponse], Any]:
# Note error formatters work on the full response dict
error_formatter_maps = (ERROR_FORMATTERS,)
formatters = combine_formatters(error_formatter_maps, method_name)
Expand Down
Loading