3
3
from typing import Optional
4
4
5
5
import eth_abi
6
+ from eth_typing import BlockIdentifier
6
7
from eth_utils import to_bytes
7
8
from eth_utils .abi import get_abi_output_types , get_abi_input_types
8
9
from web3 .contract .contract import ContractFunction , ContractConstructor
@@ -81,20 +82,23 @@ def call(
81
82
self ,
82
83
use_revert : Optional [bool ] = None ,
83
84
batch_size : int = 1_000 ,
84
- state_override : Optional [StateOverride ] = None
85
+ state_override : Optional [StateOverride ] = None ,
86
+ block_identifier : Optional [BlockIdentifier ] = None
85
87
):
86
88
results , _ = self .call_with_gas (
87
89
use_revert = use_revert ,
88
90
batch_size = batch_size ,
89
- state_override = state_override
91
+ state_override = state_override ,
92
+ block_identifier = block_identifier
90
93
)
91
94
return results
92
95
93
96
def call_with_gas (
94
97
self ,
95
98
use_revert : Optional [bool ] = None ,
96
99
batch_size : int = 1_000 ,
97
- state_override : Optional [StateOverride ] = None
100
+ state_override : Optional [StateOverride ] = None ,
101
+ block_identifier : Optional [BlockIdentifier ] = None
98
102
):
99
103
if state_override is not None :
100
104
assert self .w3 .overwrites_available
@@ -111,6 +115,7 @@ def call_with_gas(
111
115
batch_size = batch_size ,
112
116
state_overwrites = state_overwrites ,
113
117
global_state_override = state_override ,
118
+ block_identifier = block_identifier ,
114
119
)
115
120
116
121
def _inner_call (
@@ -120,6 +125,7 @@ def _inner_call(
120
125
batch_size : int ,
121
126
state_overwrites : list [StateOverride | None ],
122
127
global_state_override : StateOverride | None = None ,
128
+ block_identifier : Optional [BlockIdentifier ] = None
123
129
) -> tuple [list [Exception | tuple [any , ...]], list [int ]]:
124
130
assert len (calls_with_calldata ) == len (state_overwrites )
125
131
if len (calls_with_calldata ) == 0 :
@@ -128,6 +134,7 @@ def _inner_call(
128
134
use_revert = use_revert ,
129
135
batch_size = batch_size ,
130
136
global_state_override = global_state_override ,
137
+ block_identifier = block_identifier
131
138
)
132
139
# make sure calls are not bigger than batch_size
133
140
if len (calls_with_calldata ) > batch_size :
@@ -162,7 +169,8 @@ def _inner_call(
162
169
multicall_call = multicall_call ,
163
170
use_revert = use_revert ,
164
171
retry = False ,
165
- state_override = state_override
172
+ state_override = state_override ,
173
+ block_identifier = block_identifier
166
174
)
167
175
except Exception as e :
168
176
if len (calls_with_calldata ) == 1 :
@@ -171,7 +179,8 @@ def _inner_call(
171
179
multicall_call = multicall_call ,
172
180
use_revert = use_revert ,
173
181
retry = True ,
174
- state_override = state_override
182
+ state_override = state_override ,
183
+ block_identifier = block_identifier
175
184
)
176
185
except Exception as e :
177
186
raw_returns = [e ]
@@ -417,7 +426,8 @@ def _call_multicall(
417
426
multicall_call : ContractConstructor | ContractFunction ,
418
427
use_revert : bool ,
419
428
retry : bool = False ,
420
- state_override : Optional [StateOverride ] = None
429
+ state_override : Optional [StateOverride ] = None ,
430
+ block_identifier : Optional [BlockIdentifier ] = None
421
431
):
422
432
# call transaction
423
433
try :
@@ -427,7 +437,10 @@ def _call_multicall(
427
437
"nonce" : 0 ,
428
438
"data" : multicall_call .data_in_transaction ,
429
439
"no_retry" : not retry ,
430
- }, state_override = state_override )
440
+ },
441
+ state_override = state_override ,
442
+ block_identifier = block_identifier
443
+ )
431
444
else :
432
445
assert isinstance (multicall_call , ContractFunction )
433
446
# manually encoding and decoding call because web3.py is sooooo slow...
@@ -446,7 +459,10 @@ def _call_multicall(
446
459
"nonce" : 0 ,
447
460
"data" : calldata ,
448
461
"no_retry" : not retry ,
449
- }, state_override = state_override )
462
+ },
463
+ state_override = state_override ,
464
+ block_identifier = block_identifier
465
+ )
450
466
_ , multicall_result = eth_abi .decode (get_abi_output_types (multicall_call .abi ), raw_response )
451
467
452
468
if len (multicall_result ) > 0 and self .undeployed_contract_constructor is not None :
0 commit comments