Skip to content

Commit

Permalink
Add get_transaction_by_block, deprecate getTransactionByBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed Jan 29, 2021
1 parent c7d2761 commit c7cfaaa
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ API
- :meth:`web3.eth.get_proof() <web3.eth.Eth.get_proof>`
- :meth:`web3.eth.get_storage_at() <web3.eth.Eth.get_storage_at>`
- :meth:`web3.eth.get_transaction() <web3.eth.Eth.get_transaction>`
- :meth:`web3.eth.getTransactionByBlock() <web3.eth.Eth.getTransactionByBlock>`
- :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.getUncleCount() <web3.eth.Eth.getUncleCount>`
Expand Down
10 changes: 7 additions & 3 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ The following methods are available on the ``web3.eth`` namespace.
.. note:: This method is deprecated in EIP 1474.


.. py:method:: Eth.getTransactionByBlock(block_identifier, transaction_index)
.. py:method:: Eth.get_transaction_by_block(block_identifier, transaction_index)
* Delegates to ``eth_getTransactionByBlockNumberAndIndex`` or
``eth_getTransactionByBlockHashAndIndex`` RPC Methods
Expand All @@ -571,7 +571,7 @@ The following methods are available on the ``web3.eth`` namespace.

.. code-block:: python
>>> web3.eth.getTransactionFromBlock(46147, 0)
>>> web3.eth.get_transaction_by_block(46147, 0)
AttributeDict({
'blockHash': '0x4e3a3754410177e6937ef1f84bba68ea139e8d1a2258c5f85db9f1cd715a1bdd',
'blockNumber': 46147,
Expand All @@ -585,7 +585,7 @@ The following methods are available on the ``web3.eth`` namespace.
'transactionIndex': 0,
'value': 31337,
})
>>> web3.eth.getTransactionFromBlock('0x4e3a3754410177e6937ef1f84bba68ea139e8d1a2258c5f85db9f1cd715a1bdd', 0)
>>> web3.eth.get_transaction_by_block('0x4e3a3754410177e6937ef1f84bba68ea139e8d1a2258c5f85db9f1cd715a1bdd', 0)
AttributeDict({
'blockHash': '0x4e3a3754410177e6937ef1f84bba68ea139e8d1a2258c5f85db9f1cd715a1bdd',
'blockNumber': 46147,
Expand All @@ -600,6 +600,10 @@ The following methods are available on the ``web3.eth`` namespace.
'value': 31337,
})
.. py:method:: Eth.getTransactionByBlock(block_identifier, transaction_index)
.. warning:: Deprecated: This method is deprecated in favor of
:attr:`~web3.eth.Eth.get_transaction_by_block`

.. py:method:: Eth.waitForTransactionReceipt(transaction_hash, timeout=120, poll_latency=0.1)
Expand Down
1 change: 1 addition & 0 deletions newsfragments/1859.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``eth.get_transaction_by_block``, deprecate ``eth.getTransactionByBlock``
26 changes: 24 additions & 2 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,14 +1006,36 @@ def test_eth_getTransactionByHash_contract_creation(
def test_eth_getTransactionByBlockHashAndIndex(
self, web3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr
) -> None:
transaction = web3.eth.getTransactionByBlock(block_with_txn['hash'], 0)
transaction = web3.eth.get_transaction_by_block(block_with_txn['hash'], 0)
assert is_dict(transaction)
assert transaction['hash'] == HexBytes(mined_txn_hash)

def test_eth_getTransactionByBlockHashAndIndex_deprecated(
self, web3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr
) -> None:
with pytest.warns(
DeprecationWarning,
match='getTransactionByBlock is deprecated in favor of get_transaction_by_block'
):
transaction = web3.eth.getTransactionByBlock(block_with_txn['hash'], 0)
assert is_dict(transaction)
assert transaction['hash'] == HexBytes(mined_txn_hash)

def test_eth_getTransactionByBlockNumberAndIndex(
self, web3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr
) -> None:
transaction = web3.eth.getTransactionByBlock(block_with_txn['number'], 0)
transaction = web3.eth.get_transaction_by_block(block_with_txn['number'], 0)
assert is_dict(transaction)
assert transaction['hash'] == HexBytes(mined_txn_hash)

def test_eth_getTransactionByBlockNumberAndIndex_deprecated(
self, web3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr
) -> None:
with pytest.warns(
DeprecationWarning,
match='getTransactionByBlock is deprecated in favor of get_transaction_by_block'
):
transaction = web3.eth.getTransactionByBlock(block_with_txn['number'], 0)
assert is_dict(transaction)
assert transaction['hash'] == HexBytes(mined_txn_hash)

Expand Down
5 changes: 4 additions & 1 deletion web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def getTransactionFromBlock(
"""
raise DeprecationWarning("This method has been deprecated as of EIP 1474.")

getTransactionByBlock: Method[Callable[[BlockIdentifier, int], TxData]] = Method(
get_transaction_by_block: Method[Callable[[BlockIdentifier, int], TxData]] = Method(
method_choice_depends_on_args=select_method_for_block_identifier(
if_predefined=RPC.eth_getTransactionByBlockNumberAndIndex,
if_hash=RPC.eth_getTransactionByBlockHashAndIndex,
Expand Down Expand Up @@ -656,3 +656,6 @@ def setGasPriceStrategy(self, gas_price_strategy: GasPriceStrategy) -> None:
getCode = DeprecatedMethod(get_code, 'getCode', 'get_code')
getProof = DeprecatedMethod(get_proof, 'getProof', 'get_proof')
getTransaction = DeprecatedMethod(get_transaction, 'getTransaction', 'get_transaction')
getTransactionByBlock = DeprecatedMethod(get_transaction_by_block,
'getTransactionByBlock',
'get_transaction_by_block')

0 comments on commit c7cfaaa

Please sign in to comment.