@@ -1134,7 +1134,7 @@ func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrO
1134
1134
return result .Return (), result .Err
1135
1135
}
1136
1136
1137
- func DoEstimateGas (ctx context.Context , b Backend , args TransactionArgs , blockNrOrHash rpc.BlockNumberOrHash , gasCap uint64 ) (hexutil.Uint64 , error ) {
1137
+ func DoEstimateGas (ctx context.Context , b Backend , args TransactionArgs , blockNrOrHash rpc.BlockNumberOrHash , overrides * StateOverride , gasCap uint64 ) (hexutil.Uint64 , error ) {
1138
1138
// Binary search the gas requirement, as it may be higher than the amount used
1139
1139
var (
1140
1140
lo uint64 = params .TxGas - 1
@@ -1176,6 +1176,10 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
1176
1176
if err != nil {
1177
1177
return 0 , err
1178
1178
}
1179
+ err = overrides .Apply (state )
1180
+ if err != nil {
1181
+ return 0 , err
1182
+ }
1179
1183
balance := state .GetBalance (* args .From ) // from can't be nil
1180
1184
available := new (big.Int ).Set (balance )
1181
1185
if args .Value != nil {
@@ -1221,6 +1225,10 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
1221
1225
if state == nil || err != nil {
1222
1226
return 0 , err
1223
1227
}
1228
+ err = overrides .Apply (state )
1229
+ if err != nil {
1230
+ return 0 , err
1231
+ }
1224
1232
// Execute the binary search and hone in on an executable gas limit
1225
1233
for lo + 1 < hi {
1226
1234
s := state .Copy ()
@@ -1261,12 +1269,12 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
1261
1269
1262
1270
// EstimateGas returns an estimate of the amount of gas needed to execute the
1263
1271
// given transaction against the current pending block.
1264
- func (s * BlockChainAPI ) EstimateGas (ctx context.Context , args TransactionArgs , blockNrOrHash * rpc.BlockNumberOrHash ) (hexutil.Uint64 , error ) {
1272
+ func (s * BlockChainAPI ) EstimateGas (ctx context.Context , args TransactionArgs , blockNrOrHash * rpc.BlockNumberOrHash , overrides * StateOverride ) (hexutil.Uint64 , error ) {
1265
1273
bNrOrHash := rpc .BlockNumberOrHashWithNumber (rpc .LatestBlockNumber )
1266
1274
if blockNrOrHash != nil {
1267
1275
bNrOrHash = * blockNrOrHash
1268
1276
}
1269
- return DoEstimateGas (ctx , s .b , args , bNrOrHash , s .b .RPCGasCap ())
1277
+ return DoEstimateGas (ctx , s .b , args , bNrOrHash , overrides , s .b .RPCGasCap ())
1270
1278
}
1271
1279
1272
1280
// RPCMarshalHeader converts the given header to the RPC output .
0 commit comments