Skip to content

Commit 6cfe50e

Browse files
committed
Swap getBlock for get_block
1 parent eba67ce commit 6cfe50e

37 files changed

+117
-105
lines changed

docs/examples.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ Looking up blocks
1111
-----------------
1212

1313
Blocks can be looked up by either their number or hash using the
14-
``web3.eth.getBlock`` API. Block hashes should be in their hexadecimal
14+
``web3.eth.get_block`` API. Block hashes should be in their hexadecimal
1515
representation. Block numbers
1616

1717
.. code-block:: python
1818
1919
# get a block by number
20-
>>> web3.eth.getBlock(12345)
20+
>>> web3.eth.get_block(12345)
2121
{
2222
'author': '0xad5C1768e5974C231b2148169da064e61910f31a',
2323
'difficulty': 735512610763,
@@ -45,19 +45,19 @@ representation. Block numbers
4545
}
4646
4747
# get a block by it's hash
48-
>>> web3.eth.getBlock('0x767c2bfb3bdee3f78676c1285cd757bcd5d8c272cef2eb30d9733800a78c0b6d')
48+
>>> web3.eth.get_block('0x767c2bfb3bdee3f78676c1285cd757bcd5d8c272cef2eb30d9733800a78c0b6d')
4949
{...}
5050
5151
5252
Getting the latest block
5353
------------------------
5454

5555
You can also retrieve the latest block using the string ``'latest'`` in the
56-
``web3.eth.getBlock`` API.
56+
``web3.eth.get_block`` API.
5757

5858
.. code-block:: python
5959
60-
>>> web3.eth.getBlock('latest')
60+
>>> web3.eth.get_block('latest')
6161
{...}
6262
6363

docs/middleware.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ AttributeDict
3030
.. py:method:: web3.middleware.attrdict_middleware
3131
3232
This middleware converts the output of a function from a dictionary to an ``AttributeDict``
33-
which enables dot-syntax access, like ``eth.getBlock('latest').number``
34-
in addition to ``eth.getBlock('latest')['number']``.
33+
which enables dot-syntax access, like ``eth.get_block('latest').number``
34+
in addition to ``eth.get_block('latest')['number']``.
3535

3636
.eth Name Resolution
3737
~~~~~~~~~~~~~~~~~~~~~
@@ -272,7 +272,7 @@ Stalecheck
272272
273273
If the latest block in the blockchain is older than 2 days in this example, then the
274274
middleware will raise a ``StaleBlockchain`` exception on every call except
275-
``web3.eth.getBlock()``.
275+
``web3.eth.get_block()``.
276276

277277

278278
Cache

docs/overview.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ Fetching Data
133133

134134
Viewing account balances (:meth:`get_balance <web3.eth.Eth.get_balance>`), transactions
135135
(:meth:`getTransaction <web3.eth.Eth.getTransaction>`), and block data
136-
(:meth:`getBlock <web3.eth.Eth.getBlock>`) are some of the most common starting
136+
(:meth:`get_block <web3.eth.Eth.get_block>`) are some of the most common starting
137137
points in Web3.py.
138138

139139

140140
API
141141
^^^
142142

143143
- :meth:`web3.eth.get_balance() <web3.eth.Eth.get_balance>`
144-
- :meth:`web3.eth.getBlock() <web3.eth.Eth.getBlock>`
144+
- :meth:`web3.eth.get_block() <web3.eth.Eth.get_block>`
145145
- :meth:`web3.eth.getBlockTransactionCount() <web3.eth.Eth.getBlockTransactionCount>`
146146
- :meth:`web3.eth.getCode() <web3.eth.Eth.getCode>`
147147
- :meth:`web3.eth.getProof() <web3.eth.Eth.getProof>`

docs/quickstart.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ to interact with the Ethereum blockchain. Try getting all the information about
107107

108108
.. code-block:: python
109109
110-
>>> w3.eth.getBlock('latest')
110+
>>> w3.eth.get_block('latest')
111111
{'difficulty': 1,
112112
'gasLimit': 6283185,
113113
'gasUsed': 0,

docs/web3.eth.rst

+8-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ you can find the latest block number in these two ways:
1515

1616
.. code-block:: python
1717
18-
>>> block = web3.eth.getBlock('latest')
18+
>>> block = web3.eth.get_block('latest')
1919
AttributeDict({
2020
'hash': '0xe8ad537a261e6fff80d551d8d087ee0f2202da9b09b64d172a5f45e818eb472a',
2121
'number': 4022281,
@@ -303,7 +303,7 @@ The following methods are available on the ``web3.eth`` namespace.
303303
304304
return True
305305
306-
block = w3.eth.getBlock(3391)
306+
block = w3.eth.get_block(3391)
307307
proof = w3.eth.getProof('0x6C8f2A135f6ed072DE4503Bd7C4999a1a17F824B', [0, 1], 3391)
308308
assert verify_eth_getProof(proof, block.stateRoot)
309309
@@ -327,7 +327,7 @@ The following methods are available on the ``web3.eth`` namespace.
327327
'0x'
328328
329329
330-
.. py:method:: Eth.getBlock(block_identifier=eth.defaultBlock, full_transactions=False)
330+
.. py:method:: Eth.get_block(block_identifier=eth.defaultBlock, full_transactions=False)
331331
332332
* Delegates to ``eth_getBlockByNumber`` or ``eth_getBlockByHash`` RPC Methods
333333

@@ -342,7 +342,7 @@ The following methods are available on the ``web3.eth`` namespace.
342342

343343
.. code-block:: python
344344
345-
>>> web3.eth.getBlock(2000000)
345+
>>> web3.eth.get_block(2000000)
346346
AttributeDict({
347347
'difficulty': 49824742724615,
348348
'extraData': '0xe4b883e5bda9e7a59ee4bb99e9b1bc',
@@ -365,6 +365,10 @@ The following methods are available on the ``web3.eth`` namespace.
365365
'uncles': [],
366366
})
367367
368+
.. py:method:: Eth.getBlock(block_identifier=eth.defaultBlock, full_transactions=False)
369+
370+
.. warning:: Deprecated: This method is deprecated in favor of
371+
:meth:`~web3.eth.Eth.get_block`
368372

369373
.. py:method:: Eth.getBlockTransactionCount(block_identifier)
370374

ethpm/_utils/chains.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232

3333
def get_genesis_block_hash(web3: "Web3") -> HexBytes:
34-
return web3.eth.getBlock(BlockNumber(0))["hash"]
34+
return web3.eth.get_block(BlockNumber(0))["hash"]
3535

3636

3737
BLOCK = "block"

ethpm/uri.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,27 @@ def create_latest_block_uri(w3: "Web3", from_blocks_ago: int = 3) -> URI:
108108
If using a testnet with less than 3 mined blocks, adjust :from_blocks_ago:.
109109
"""
110110
chain_id = to_hex(get_genesis_block_hash(w3))
111-
latest_block_tx_receipt = w3.eth.getBlock("latest")
111+
latest_block_tx_receipt = w3.eth.get_block("latest")
112112
target_block_number = BlockNumber(latest_block_tx_receipt["number"] - from_blocks_ago)
113113
if target_block_number < 0:
114114
raise Exception(
115115
f"Only {latest_block_tx_receipt['number']} blocks avaible on provided w3, "
116116
f"cannot create latest block uri for {from_blocks_ago} blocks ago."
117117
)
118-
recent_block = to_hex(w3.eth.getBlock(target_block_number)["hash"])
118+
recent_block = to_hex(w3.eth.get_block(target_block_number)["hash"])
119119
return create_block_uri(chain_id, recent_block)
120120

121121

122122
@curry
123123
def check_if_chain_matches_chain_uri(web3: "Web3", blockchain_uri: URI) -> bool:
124124
chain_id, resource_type, resource_hash = parse_BIP122_uri(blockchain_uri)
125-
genesis_block = web3.eth.getBlock("earliest")
125+
genesis_block = web3.eth.get_block("earliest")
126126

127127
if encode_hex(genesis_block["hash"]) != chain_id:
128128
return False
129129

130130
if resource_type == BLOCK:
131-
resource = web3.eth.getBlock(resource_hash)
131+
resource = web3.eth.get_block(resource_hash)
132132
else:
133133
raise ValueError(f"Unsupported resource type: {resource_type}")
134134

tests/core/contracts/test_contract_call_interface.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def test_neg_block_indexes_from_the_end(web3, math_contract):
588588

589589

590590
def test_returns_data_from_specified_block(web3, math_contract):
591-
start_num = web3.eth.getBlock('latest').number
591+
start_num = web3.eth.get_block('latest').number
592592
web3.provider.make_request(method='evm_mine', params=[5])
593593
math_contract.functions.increment().transact()
594594
math_contract.functions.increment().transact()

tests/core/contracts/test_contract_caller_interface.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_caller_with_a_nonexistent_function(math_contract):
9999

100100

101101
def test_caller_with_block_identifier(web3, math_contract):
102-
start_num = web3.eth.getBlock('latest').number
102+
start_num = web3.eth.get_block('latest').number
103103
assert math_contract.caller.counter() == 0
104104

105105
web3.provider.make_request(method='evm_mine', params=[5])
@@ -117,7 +117,7 @@ def test_caller_with_block_identifier_and_transaction_dict(web3,
117117
caller_tester_contract,
118118
transaction_dict,
119119
address):
120-
start_num = web3.eth.getBlock('latest').number
120+
start_num = web3.eth.get_block('latest').number
121121
assert caller_tester_contract.caller.counter() == 0
122122

123123
web3.provider.make_request(method='evm_mine', params=[5])

tests/core/contracts/test_contract_util_functions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
# This tests negative block number identifiers, which behave like python
77
# list slices, with -1 being the latest block and -2 being the block before that.
88
# This test is necessary because transaction calls allow negative block indexes, although
9-
# getBlock() does not allow negative block identifiers. Support for negative block identifier
9+
# get_block() does not allow negative block identifiers. Support for negative block identifier
1010
# will likely be removed in v5.
1111
def test_parse_block_identifier_int(web3):
12-
last_num = web3.eth.getBlock('latest').number
12+
last_num = web3.eth.get_block('latest').number
1313
assert 0 == parse_block_identifier_int(web3, -1 - last_num)

tests/core/contracts/test_implicit_contract.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def math_contract(web3, MATH_ABI, MATH_CODE, MATH_RUNTIME, address_conversion_fu
3838
@pytest.fixture()
3939
def get_transaction_count(web3):
4040
def get_transaction_count(blocknum_or_label):
41-
block = web3.eth.getBlock(blocknum_or_label)
41+
block = web3.eth.get_block(blocknum_or_label)
4242
# Return the blocknum if we requested this via labels
4343
# so we can directly query the block next time (using the same API call)
4444
# Either way, return the number of transactions in the given block

tests/core/eth-module/test_poa.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ def test_long_extra_data(web3):
1616
})
1717
web3.middleware_onion.inject(return_block_with_long_extra_data, layer=0)
1818
with pytest.raises(ExtraDataLengthError):
19-
web3.eth.getBlock('latest')
19+
web3.eth.get_block('latest')
2020

2121

2222
def test_full_extra_data(web3):
2323
return_block_with_long_extra_data = construct_fixture_middleware({
2424
'eth_getBlockByNumber': {'extraData': '0x' + 'ff' * 32},
2525
})
2626
web3.middleware_onion.inject(return_block_with_long_extra_data, layer=0)
27-
block = web3.eth.getBlock('latest')
27+
block = web3.eth.get_block('latest')
2828
assert block.extraData == b'\xff' * 32
2929

3030

@@ -34,6 +34,6 @@ def test_geth_proof_of_authority(web3):
3434
})
3535
web3.middleware_onion.inject(geth_poa_middleware, layer=0)
3636
web3.middleware_onion.inject(return_block_with_long_extra_data, layer=0)
37-
block = web3.eth.getBlock('latest')
37+
block = web3.eth.get_block('latest')
3838
assert 'extraData' not in block
3939
assert block.proofOfAuthorityData == b'\xff' * 33

tests/core/filtering/test_existing_filter_instance.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ def test_instantiate_existing_filter(web3, sleep_interval, wait_for_block, filte
4040
assert len(found_block_hashes) == 3
4141

4242
expected_block_hashes = [
43-
web3.eth.getBlock(n + 1).hash for n in range(current_block, current_block + 3)
43+
web3.eth.get_block(n + 1).hash for n in range(current_block, current_block + 3)
4444
]
4545
assert found_block_hashes == expected_block_hashes

tests/core/filtering/test_filter_against_latest_blocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ def test_sync_filter_against_latest_blocks(web3, sleep_interval, wait_for_block)
2525
assert len(found_block_hashes) == 3
2626

2727
expected_block_hashes = [
28-
web3.eth.getBlock(n + 1).hash for n in range(current_block, current_block + 3)
28+
web3.eth.get_block(n + 1).hash for n in range(current_block, current_block + 3)
2929
]
3030
assert found_block_hashes == expected_block_hashes

tests/core/middleware/test_latest_block_based_cache_middleware.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def test_latest_block_based_cache_middleware_pulls_from_cache(
164164
w3.middleware_onion.add(block_data_middleware)
165165
w3.middleware_onion.add(result_generator_middleware)
166166

167-
current_block_hash = w3.eth.getBlock('latest')['hash']
167+
current_block_hash = w3.eth.get_block('latest')['hash']
168168

169169
def cache_class():
170170
return {

tests/core/mining-module/test_miner_setExtra.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
def test_miner_set_extra(web3_empty, wait_for_block):
1818
web3 = web3_empty
1919

20-
initial_extra = decode_hex(web3.eth.getBlock(web3.eth.blockNumber)['extraData'])
20+
initial_extra = decode_hex(web3.eth.get_block(web3.eth.blockNumber)['extraData'])
2121

2222
new_extra_data = b'-this-is-32-bytes-of-extra-data-'
2323

@@ -28,12 +28,12 @@ def test_miner_set_extra(web3_empty, wait_for_block):
2828

2929
with Timeout(60) as timeout:
3030
while True:
31-
extra_data = decode_hex(web3.eth.getBlock(web3.eth.blockNumber)['extraData'])
31+
extra_data = decode_hex(web3.eth.get_block(web3.eth.blockNumber)['extraData'])
3232
if extra_data == new_extra_data:
3333
break
3434
timeout.sleep(random.random())
3535

36-
after_extra = decode_hex(web3.eth.getBlock(web3.eth.blockNumber)['extraData'])
36+
after_extra = decode_hex(web3.eth.get_block(web3.eth.blockNumber)['extraData'])
3737

3838
assert after_extra == new_extra_data
3939

@@ -42,7 +42,7 @@ def test_miner_set_extra(web3_empty, wait_for_block):
4242
def test_miner_setExtra(web3_empty, wait_for_block):
4343
web3 = web3_empty
4444

45-
initial_extra = decode_hex(web3.eth.getBlock(web3.eth.blockNumber)['extraData'])
45+
initial_extra = decode_hex(web3.eth.get_block(web3.eth.blockNumber)['extraData'])
4646

4747
new_extra_data = b'-this-is-32-bytes-of-extra-data-'
4848

@@ -53,10 +53,10 @@ def test_miner_setExtra(web3_empty, wait_for_block):
5353
web3.geth.miner.setExtra(new_extra_data)
5454
with Timeout(60) as timeout:
5555
while True:
56-
extra_data = decode_hex(web3.eth.getBlock(web3.eth.blockNumber)['extraData'])
56+
extra_data = decode_hex(web3.eth.get_block(web3.eth.blockNumber)['extraData'])
5757
if extra_data == new_extra_data:
5858
break
5959
timeout.sleep(random.random())
6060

61-
after_extra = decode_hex(web3.eth.getBlock(web3.eth.blockNumber)['extraData'])
61+
after_extra = decode_hex(web3.eth.get_block(web3.eth.blockNumber)['extraData'])
6262
assert after_extra == new_extra_data

tests/core/providers/test_ipc_provider.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@ def test_web3_auto_gethdev():
9292
'eth_getBlockByNumber': {'extraData': '0x' + 'ff' * 33},
9393
})
9494
w3.middleware_onion.inject(return_block_with_long_extra_data, layer=0)
95-
block = w3.eth.getBlock('latest')
95+
block = w3.eth.get_block('latest')
9696
assert 'extraData' not in block
9797
assert block.proofOfAuthorityData == b'\xff' * 33
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
def test_testing_mine_single_block(web3):
22
web3.testing.mine()
33

4-
before_mining_block = web3.eth.getBlock("latest")
4+
before_mining_block = web3.eth.get_block("latest")
55

66
web3.testing.mine()
77

8-
after_mining_block = web3.eth.getBlock("latest")
8+
after_mining_block = web3.eth.get_block("latest")
99

1010
assert after_mining_block['number'] - before_mining_block['number'] == 1
1111

1212

1313
def test_testing_mine_multiple_blocks(web3):
1414
web3.testing.mine()
1515

16-
before_mining_block = web3.eth.getBlock("latest")
16+
before_mining_block = web3.eth.get_block("latest")
1717

1818
web3.testing.mine(5)
1919

20-
after_mining_block = web3.eth.getBlock("latest")
20+
after_mining_block = web3.eth.get_block("latest")
2121

2222
assert after_mining_block['number'] - before_mining_block['number'] == 5

0 commit comments

Comments
 (0)