1- use super :: { backend:: mem:: BlockRequest , sign:: build_typed_transaction} ;
1+ use super :: {
2+ backend:: mem:: { state, BlockRequest } ,
3+ sign:: build_typed_transaction,
4+ } ;
25use crate :: {
36 eth:: {
47 backend,
@@ -228,8 +231,8 @@ impl EthApi {
228231 EthRequest :: EthCreateAccessList ( call, block) => {
229232 self . create_access_list ( call, block) . await . to_rpc_result ( )
230233 }
231- EthRequest :: EthEstimateGas ( call, block) => {
232- self . estimate_gas ( call, block) . await . to_rpc_result ( )
234+ EthRequest :: EthEstimateGas ( call, block, overrides ) => {
235+ self . estimate_gas ( call, block, overrides ) . await . to_rpc_result ( )
233236 }
234237 EthRequest :: EthGetTransactionByBlockHashAndIndex ( hash, index) => {
235238 self . transaction_by_block_hash_and_index ( hash, index) . await . to_rpc_result ( )
@@ -860,7 +863,9 @@ impl EthApi {
860863
861864 if request. gas . is_none ( ) {
862865 // estimate if not provided
863- if let Ok ( gas) = self . estimate_gas ( request. clone ( ) . into_call_request ( ) , None ) . await {
866+ if let Ok ( gas) =
867+ self . estimate_gas ( request. clone ( ) . into_call_request ( ) , None , None ) . await
868+ {
864869 request. gas = Some ( gas) ;
865870 }
866871 }
@@ -886,7 +891,9 @@ impl EthApi {
886891
887892 if request. gas . is_none ( ) {
888893 // estimate if not provided
889- if let Ok ( gas) = self . estimate_gas ( request. clone ( ) . into_call_request ( ) , None ) . await {
894+ if let Ok ( gas) =
895+ self . estimate_gas ( request. clone ( ) . into_call_request ( ) , None , None ) . await
896+ {
890897 request. gas = Some ( gas) ;
891898 }
892899 }
@@ -1081,10 +1088,15 @@ impl EthApi {
10811088 & self ,
10821089 request : CallRequest ,
10831090 block_number : Option < BlockId > ,
1091+ overrides : Option < StateOverride > ,
10841092 ) -> Result < U256 > {
10851093 node_info ! ( "eth_estimateGas" ) ;
1086- self . do_estimate_gas ( request, block_number. or_else ( || Some ( BlockNumber :: Pending . into ( ) ) ) )
1087- . await
1094+ self . do_estimate_gas (
1095+ request,
1096+ block_number. or_else ( || Some ( BlockNumber :: Pending . into ( ) ) ) ,
1097+ overrides,
1098+ )
1099+ . await
10881100 }
10891101
10901102 /// Get transaction by its hash.
@@ -2144,12 +2156,18 @@ impl EthApi {
21442156 & self ,
21452157 request : CallRequest ,
21462158 block_number : Option < BlockId > ,
2159+ overrides : Option < StateOverride > ,
21472160 ) -> Result < U256 > {
21482161 let block_request = self . block_request ( block_number) . await ?;
21492162 // check if the number predates the fork, if in fork mode
21502163 if let BlockRequest :: Number ( number) = block_request {
21512164 if let Some ( fork) = self . get_fork ( ) {
21522165 if fork. predates_fork ( number) {
2166+ if overrides. is_some ( ) {
2167+ return Err ( BlockchainError :: StateOverrideError (
2168+ "not available on past forked blocks" . to_string ( ) ,
2169+ ) ) ;
2170+ }
21532171 return fork
21542172 . estimate_gas ( & request, Some ( number. into ( ) ) )
21552173 . await
@@ -2159,7 +2177,13 @@ impl EthApi {
21592177 }
21602178
21612179 self . backend
2162- . with_database_at ( Some ( block_request) , |state, block| {
2180+ . with_database_at ( Some ( block_request) , |mut state, block| {
2181+ if let Some ( overrides) = overrides {
2182+ state = Box :: new ( state:: apply_state_override (
2183+ overrides. into_iter ( ) . collect ( ) ,
2184+ state,
2185+ ) ?) ;
2186+ }
21632187 self . do_estimate_gas_with_state ( request, state, block)
21642188 } )
21652189 . await ?
0 commit comments