Skip to content

Commit c41e6fa

Browse files
committed
🎉 first commit.
Signed-off-by: Harmouch101 <eng.mahmoudharmouch@gmail.com>
1 parent 81427e6 commit c41e6fa

File tree

10 files changed

+63
-1
lines changed

10 files changed

+63
-1
lines changed

docs/providers.rst

+1
Original file line numberDiff line numberDiff line change
@@ -423,6 +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>`
426427
- :meth:`web3.eth.estimate_gas() <web3.eth.Eth.estimate_gas>`
427428
- :meth:`web3.eth.generate_gas_price() <web3.eth.Eth.generate_gas_price>`
428429
- :meth:`web3.eth.get_balance() <web3.eth.Eth.get_balance>`

docs/web3.eth.rst

+32
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,38 @@ 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)
1082+
1083+
* Delegates to ``eth_createAccessList`` RPC Method
1084+
1085+
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.
1086+
1087+
:param transaction: ``TransactionCall`` object.
1088+
:param block_identifier: Optional, blocknumber or ``latest`` or ``pending``
1089+
1090+
.. code-block:: python
1091+
1092+
>>> we3.eth.createAccessList({'from': '0x0', 'data': '0x0'})
1093+
{
1094+
'accessList': (
1095+
{
1096+
'address': '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae',
1097+
'storageKeys': (
1098+
'0x0000000000000000000000000000000000000000000000000000000000000003',
1099+
'0x0000000000000000000000000000000000000000000000000000000000000007',
1100+
)
1101+
},
1102+
{
1103+
'address': '0xbb9bc244d798123fde783fcc1c72d3bb8c189413',
1104+
'storageKeys': ()
1105+
},
1106+
),
1107+
"gas": "21000"
1108+
}
1109+
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.
1111+
1112+
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.
10811113

10821114
.. py:method:: Eth.fee_history(block_count, newest_block, reward_percentiles=None)
10831115

tests/core/middleware/test_transaction_signing.py

+2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ 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'),
138140
('eth_sendTransaction', SAME_KEY_SAME_TYPE, hex_to_bytes(ADDRESS_1),
139141
'eth_sendRawTransaction'),
140142
)

web3/_utils/method_formatters.py

+12
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,16 @@ def apply_list_to_array_formatter(formatter: Any) -> Callable[..., Any]:
372372

373373
signed_tx_formatter = apply_formatters_to_dict(SIGNED_TX_FORMATTER)
374374

375+
ACCESS_LIST_FORMATTER = apply_list_to_array_formatter({
376+
'address': to_checksum_address,
377+
'storageKeys': apply_list_to_array_formatter(to_hexbytes(64))
378+
})
379+
380+
ACCESS_LIST_RESPONCE_FORMATTER = apply_formatters_to_dict({
381+
"accessList": ACCESS_LIST_FORMATTER,
382+
"gasUsed": to_integer_if_hex,
383+
})
384+
375385
FILTER_PARAM_NORMALIZERS = apply_formatters_to_dict({
376386
'address': apply_formatter_if(is_string, lambda x: [x])
377387
})
@@ -426,6 +436,7 @@ def apply_list_to_array_formatter(formatter: Any) -> Callable[..., Any]:
426436
(is_length(2), call_without_override),
427437
(is_length(3), call_with_override),
428438
)),
439+
RPC.eth_createAccessList: apply_formatter_at_index(transaction_param_formatter, 0),
429440
RPC.eth_estimateGas: apply_one_of_formatters((
430441
(is_length(1), estimate_gas_without_block_id),
431442
(is_length(2), estimate_gas_with_block_id),
@@ -459,6 +470,7 @@ def apply_list_to_array_formatter(formatter: Any) -> Callable[..., Any]:
459470
RPC.eth_chainId: to_integer_if_hex,
460471
RPC.eth_coinbase: to_checksum_address,
461472
RPC.eth_call: HexBytes,
473+
RPC.eth_createAccessList: ACCESS_LIST_RESPONCE_FORMATTER,
462474
RPC.eth_estimateGas: to_integer_if_hex,
463475
RPC.eth_feeHistory: fee_history_formatter,
464476
RPC.eth_maxPriorityFeePerGas: to_integer_if_hex,

web3/_utils/rpc_abi.py

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +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")
4647
eth_chainId = RPCEndpoint("eth_chainId")
4748
eth_coinbase = RPCEndpoint("eth_coinbase")
4849
eth_estimateGas = RPCEndpoint("eth_estimateGas")
@@ -178,6 +179,7 @@ class RPC:
178179
RPC_ABIS = {
179180
# eth
180181
'eth_call': TRANSACTION_PARAMS_ABIS,
182+
'eth_createAccessList': TRANSACTION_PARAMS_ABIS,
181183
'eth_estimateGas': TRANSACTION_PARAMS_ABIS,
182184
'eth_getBalance': ['address', None],
183185
'eth_getBlockByHash': ['bytes32', 'bool'],

web3/eth.py

+5
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,11 @@ def sign_munger(
868868
mungers=[BaseEth.call_munger]
869869
)
870870

871+
createAccessList: Method[Callable[..., Union[bytes, bytearray]]] = Method(
872+
RPC.eth_createAccessList,
873+
mungers=[BaseEth.call_munger]
874+
)
875+
871876
def estimate_gas(
872877
self,
873878
transaction: TxParams,

web3/middleware/cache.py

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

web3/middleware/exception_retry_request.py

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
'eth_getTransactionCount',
5454
'eth_getRawTransactionByHash',
5555
'eth_call',
56+
'eth_createAccessList',
5657
'eth_estimateGas',
5758
'eth_newBlockFilter',
5859
'eth_newPendingTransactionFilter',

web3/middleware/validation.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ def _transaction_param_validator(web3_chain_id: int) -> Callable[..., Any]:
113113
METHODS_TO_VALIDATE = [
114114
RPC.eth_sendTransaction,
115115
RPC.eth_estimateGas,
116-
RPC.eth_call
116+
RPC.eth_call,
117+
RPC.eth_createAccessList
117118
]
118119

119120

web3/providers/eth_tester/middleware.py

+5
Original file line numberDiff line numberDiff line change
@@ -224,6 +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(
228+
transaction_request_transformer,
229+
apply_formatter_if(is_not_named_block, to_integer_if_hex),
230+
)
227231
RPCEndpoint('eth_uninstallFilter'): apply_formatters_to_args(hex_to_integer),
228232
RPCEndpoint('eth_getCode'): apply_formatters_to_args(
229233
identity,
@@ -323,6 +327,7 @@ def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
323327
'eth_call',
324328
'eth_estimateGas',
325329
'eth_sendTransaction',
330+
'eth_createAccessList',
326331
):
327332
filled_transaction = pipe(
328333
params[0],

0 commit comments

Comments
 (0)