Skip to content

Commit cd2d875

Browse files
committed
⚡ Update.
Signed-off-by: Harmouch101 <eng.mahmoudharmouch@gmail.com>
1 parent c41e6fa commit cd2d875

File tree

10 files changed

+100
-21
lines changed

10 files changed

+100
-21
lines changed

docs/providers.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ Eth
423423
- :meth:`web3.eth.mining <web3.eth.Eth.mining>`
424424
- :meth:`web3.eth.syncing <web3.eth.Eth.syncing>`
425425
- :meth:`web3.eth.call() <web3.eth.Eth.call>`
426-
- :meth:`web3.eth.createAccessList() <web3.eth.Eth.createAccessList>`
426+
- :meth:`web3.eth.create_access_list() <web3.eth.Eth.create_access_list>`
427427
- :meth:`web3.eth.estimate_gas() <web3.eth.Eth.estimate_gas>`
428428
- :meth:`web3.eth.generate_gas_price() <web3.eth.Eth.generate_gas_price>`
429429
- :meth:`web3.eth.get_balance() <web3.eth.Eth.get_balance>`

docs/web3.eth.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ The following methods are available on the ``web3.eth`` namespace.
10691069
>>> myContract.functions.getVar().call()
10701070
1
10711071
# The above call equivalent to the raw call:
1072-
>>> we3.eth.call({'value': 0, 'gas': 21736, 'maxFeePerGas': 2000000000, 'maxPriorityFeePerGas': 1000000000, 'to': '0xc305c901078781C232A2a521C2aF7980f8385ee9', 'data': '0x477a5c98'})
1072+
>>> w3.eth.call({'value': 0, 'gas': 21736, 'maxFeePerGas': 2000000000, 'maxPriorityFeePerGas': 1000000000, 'to': '0xc305c901078781C232A2a521C2aF7980f8385ee9', 'data': '0x477a5c98'})
10731073
HexBytes('0x0000000000000000000000000000000000000000000000000000000000000001')
10741074
10751075
In most cases it is better to make contract function call through the :py:class:`web3.contract.Contract` interface.
@@ -1078,18 +1078,18 @@ The following methods are available on the ``web3.eth`` namespace.
10781078
View their `usage documentation <https://geth.ethereum.org/docs/rpc/ns-eth#3-object---state-override-set>`_
10791079
for a list of possible parameters.
10801080

1081-
.. py:method:: Eth.createAccessList(transaction, block_identifier=web3.eth.default_block)
1081+
.. py:method:: Eth.create_access_list(transaction, block_identifier=web3.eth.default_block)
10821082
1083-
* Delegates to ``eth_createAccessList`` RPC Method
1083+
* Delegates to ``eth_create_access_list`` RPC Method
10841084

10851085
This method creates an `EIP2930 <https://eips.ethereum.org/EIPS/eip-2930>`_ type ``accessList`` based on a given ``Transaction``. The ``accessList`` contains all storage slots and addresses read and written by the transaction, except for the sender account and the precompiles. This method uses the same ``transaction`` call object and ``block_identifier`` object as :meth:`~web3.eth.Eth.call()`. An ``accessList`` can be used to unstuck contracts that became inaccessible due to gas cost increases.
10861086

10871087
:param transaction: ``TransactionCall`` object.
1088-
:param block_identifier: Optional, blocknumber or ``latest`` or ``pending``
1088+
:param block_identifier: Optional, a block_number or ``latest`` or ``pending``
10891089

10901090
.. code-block:: python
10911091
1092-
>>> we3.eth.createAccessList({'from': '0x0', 'data': '0x0'})
1092+
>>> w3.eth.create_access_list({'from': '0x0', 'data': '0x0', 'type': '0x1'})
10931093
{
10941094
'accessList': (
10951095
{
@@ -1107,7 +1107,7 @@ The following methods are available on the ``web3.eth`` namespace.
11071107
"gas": "21000"
11081108
}
11091109
1110-
The method ``eth_createAccessList`` returns list of addresses and storage keys used by the transaction, plus the gas consumed when the access list is added.
1110+
The method ``eth_create_access_list`` returns list of addresses and storage keys used by the transaction, plus the gas consumed when the access list is added.
11111111

11121112
That is, it gives you the list of addresses and storage keys that will be used by that transaction, plus the gas consumed if the access list is included. Like ``eth_estimateGas``, this is an estimation; the list could change when the transaction is actually mined. Adding an ``accessList`` to your transaction does not necessary result in lower gas usage compared to a transaction without an access list.
11131113

tests/core/middleware/test_transaction_signing.py

-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ def hex_to_bytes(s):
135135
('eth_sendTransaction', SAME_KEY_MIXED_TYPE[3], ADDRESS_2, NotImplementedError),
136136
('eth_sendTransaction', SAME_KEY_MIXED_TYPE[4], ADDRESS_2, NotImplementedError),
137137
('eth_call', MIXED_KEY_MIXED_TYPE, ADDRESS_1, NotImplementedError),
138-
('createAccessList', SAME_KEY_SAME_TYPE, hex_to_bytes(ADDRESS_1),
139-
'eth_createAccessList'),
140138
('eth_sendTransaction', SAME_KEY_SAME_TYPE, hex_to_bytes(ADDRESS_1),
141139
'eth_sendRawTransaction'),
142140
)

web3/_utils/method_formatters.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def apply_list_to_array_formatter(formatter: Any) -> Callable[..., Any]:
436436
(is_length(2), call_without_override),
437437
(is_length(3), call_with_override),
438438
)),
439-
RPC.eth_createAccessList: apply_formatter_at_index(transaction_param_formatter, 0),
439+
RPC.eth_create_access_list: apply_formatter_at_index(transaction_param_formatter, 0),
440440
RPC.eth_estimateGas: apply_one_of_formatters((
441441
(is_length(1), estimate_gas_without_block_id),
442442
(is_length(2), estimate_gas_with_block_id),
@@ -470,7 +470,7 @@ def apply_list_to_array_formatter(formatter: Any) -> Callable[..., Any]:
470470
RPC.eth_chainId: to_integer_if_hex,
471471
RPC.eth_coinbase: to_checksum_address,
472472
RPC.eth_call: HexBytes,
473-
RPC.eth_createAccessList: ACCESS_LIST_RESPONCE_FORMATTER,
473+
RPC.eth_create_access_list: ACCESS_LIST_RESPONCE_FORMATTER,
474474
RPC.eth_estimateGas: to_integer_if_hex,
475475
RPC.eth_feeHistory: fee_history_formatter,
476476
RPC.eth_maxPriorityFeePerGas: to_integer_if_hex,

web3/_utils/module_testing/eth_module.py

+66
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,34 @@
7575
UNKNOWN_ADDRESS = ChecksumAddress(HexAddress(HexStr('0xdEADBEeF00000000000000000000000000000000')))
7676
UNKNOWN_HASH = HexStr('0xdeadbeef00000000000000000000000000000000000000000000000000000000')
7777

78+
RLP_ACCESS_LIST = [
79+
(
80+
'0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae',
81+
(
82+
'0x0000000000000000000000000000000000000000000000000000000000000003',
83+
'0x0000000000000000000000000000000000000000000000000000000000000007',
84+
)
85+
),
86+
(
87+
'0xbb9bc244d798123fde783fcc1c72d3bb8c189413',
88+
()
89+
)
90+
]
91+
92+
RPC_ACCESS_LIST = [
93+
{
94+
'address': '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae',
95+
'storageKeys': (
96+
'0x0000000000000000000000000000000000000000000000000000000000000003',
97+
'0x0000000000000000000000000000000000000000000000000000000000000007',
98+
)
99+
},
100+
{
101+
'address': '0xbb9bc244d798123fde783fcc1c72d3bb8c189413',
102+
'storageKeys': ()
103+
}
104+
]
105+
78106
if TYPE_CHECKING:
79107
from web3 import Web3 # noqa: F401
80108
from web3.contract import Contract # noqa: F401
@@ -3303,3 +3331,41 @@ def test_default_block(
33033331

33043332
# reset to default
33053333
w3.eth.default_block = 'latest'
3334+
3335+
@pytest.mark.parametrize(
3336+
'rlp_access_list',
3337+
(RLP_ACCESS_LIST,)
3338+
)
3339+
def test_create_rlp_access_list(
3340+
self, w3: "Web3", rlp_access_list, unlocked_account_dual_type: ChecksumAddress
3341+
) -> None:
3342+
txn_params: TxParams = {
3343+
'from': unlocked_account_dual_type,
3344+
'to': unlocked_account_dual_type,
3345+
'type': '0x2',
3346+
'value': 3,
3347+
'data': '0x2'
3348+
}
3349+
access_list = w3.eth.create_access_list(txn_params)
3350+
assert isinstance(access_list['accessList'][0], tuple)
3351+
assert rlp_access_list == access_list['accessList']
3352+
assert access_list['gas'] > 0
3353+
3354+
@pytest.mark.parametrize(
3355+
'rpc_access_list',
3356+
(RPC_ACCESS_LIST,)
3357+
)
3358+
def test_create_rpc_access_list(
3359+
self, w3: "Web3", rpc_access_list, unlocked_account_dual_type
3360+
) -> None:
3361+
txn_params: TxParams = {
3362+
'from': unlocked_account_dual_type,
3363+
'to': unlocked_account_dual_type,
3364+
'type': '0x1',
3365+
'value': 3,
3366+
'data': '0x2'
3367+
}
3368+
access_list = w3.eth.create_access_list(txn_params)
3369+
assert isinstance(access_list['accessList'][0], dict)
3370+
assert rpc_access_list == access_list['accessList']
3371+
assert access_list['gas'] > 0

web3/_utils/rpc_abi.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class RPC:
4343
eth_accounts = RPCEndpoint("eth_accounts")
4444
eth_blockNumber = RPCEndpoint("eth_blockNumber")
4545
eth_call = RPCEndpoint("eth_call")
46-
eth_createAccessList = RPCEndpoint("eth_createAccessList")
46+
eth_create_access_list = RPCEndpoint("eth_create_access_list")
4747
eth_chainId = RPCEndpoint("eth_chainId")
4848
eth_coinbase = RPCEndpoint("eth_coinbase")
4949
eth_estimateGas = RPCEndpoint("eth_estimateGas")
@@ -179,7 +179,7 @@ class RPC:
179179
RPC_ABIS = {
180180
# eth
181181
'eth_call': TRANSACTION_PARAMS_ABIS,
182-
'eth_createAccessList': TRANSACTION_PARAMS_ABIS,
182+
'eth_create_access_list': TRANSACTION_PARAMS_ABIS,
183183
'eth_estimateGas': TRANSACTION_PARAMS_ABIS,
184184
'eth_getBalance': ['address', None],
185185
'eth_getBlockByHash': ['bytes32', 'bool'],

web3/eth.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,21 @@ def call_munger(
313313
else:
314314
return (transaction, block_identifier, state_override)
315315

316+
def create_access_list_munger(
317+
self,
318+
transaction: TxParams,
319+
block_identifier: Optional[BlockIdentifier] = None
320+
) -> Tuple[TxParams, BlockIdentifier]:
321+
# TODO: move to middleware
322+
if 'from' not in transaction and is_checksum_address(self.default_account):
323+
transaction = assoc(transaction, 'from', self.default_account)
324+
325+
# TODO: move to middleware
326+
if block_identifier is None:
327+
block_identifier = self.default_block
328+
329+
return (transaction, block_identifier)
330+
316331
_get_accounts: Method[Callable[[], Tuple[ChecksumAddress]]] = Method(
317332
RPC.eth_accounts,
318333
mungers=None,
@@ -868,9 +883,9 @@ def sign_munger(
868883
mungers=[BaseEth.call_munger]
869884
)
870885

871-
createAccessList: Method[Callable[..., Union[bytes, bytearray]]] = Method(
872-
RPC.eth_createAccessList,
873-
mungers=[BaseEth.call_munger]
886+
create_access_list: Method[Callable[..., Union[bytes, bytearray]]] = Method(
887+
RPC.eth_create_access_list,
888+
mungers=[BaseEth.create_access_list_munger]
874889
)
875890

876891
def estimate_gas(

web3/middleware/cache.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
284284
# 'eth_sendTransaction',
285285
# 'eth_sendRawTransaction',
286286
'eth_call',
287-
'eth_createAccessList',
287+
'eth_create_access_list',
288288
'eth_estimateGas',
289289
# 'eth_getBlockByHash',
290290
'eth_getBlockByNumber',

web3/middleware/exception_retry_request.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
'eth_getTransactionCount',
5454
'eth_getRawTransactionByHash',
5555
'eth_call',
56-
'eth_createAccessList',
56+
'eth_create_access_list',
5757
'eth_estimateGas',
5858
'eth_newBlockFilter',
5959
'eth_newPendingTransactionFilter',

web3/providers/eth_tester/middleware.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ def is_hexstr(value: Any) -> bool:
224224
transaction_request_transformer,
225225
apply_formatter_if(is_not_named_block, to_integer_if_hex),
226226
),
227-
RPCEndpoint('eth_createAccessList'): apply_formatters_to_args(
227+
RPCEndpoint('eth_create_access_list'): apply_formatters_to_args(
228228
transaction_request_transformer,
229229
apply_formatter_if(is_not_named_block, to_integer_if_hex),
230-
)
230+
),
231231
RPCEndpoint('eth_uninstallFilter'): apply_formatters_to_args(hex_to_integer),
232232
RPCEndpoint('eth_getCode'): apply_formatters_to_args(
233233
identity,
@@ -327,7 +327,7 @@ def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
327327
'eth_call',
328328
'eth_estimateGas',
329329
'eth_sendTransaction',
330-
'eth_createAccessList',
330+
'eth_create_access_list',
331331
):
332332
filled_transaction = pipe(
333333
params[0],

0 commit comments

Comments
 (0)