@@ -1134,7 +1134,7 @@ func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrO
11341134	return  result .Return (), result .Err 
11351135}
11361136
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 ) {
11381138	// Binary search the gas requirement, as it may be higher than the amount used 
11391139	var  (
11401140		lo   uint64  =  params .TxGas  -  1 
@@ -1176,6 +1176,10 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
11761176		if  err  !=  nil  {
11771177			return  0 , err 
11781178		}
1179+ 		err  =  overrides .Apply (state )
1180+ 		if  err  !=  nil  {
1181+ 			return  0 , err 
1182+ 		}
11791183		balance  :=  state .GetBalance (* args .From ) // from can't be nil 
11801184		available  :=  new (big.Int ).Set (balance )
11811185		if  args .Value  !=  nil  {
@@ -1221,6 +1225,10 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
12211225	if  state  ==  nil  ||  err  !=  nil  {
12221226		return  0 , err 
12231227	}
1228+ 	err  =  overrides .Apply (state )
1229+ 	if  err  !=  nil  {
1230+ 		return  0 , err 
1231+ 	}
12241232	// Execute the binary search and hone in on an executable gas limit 
12251233	for  lo + 1  <  hi  {
12261234		s  :=  state .Copy ()
@@ -1261,12 +1269,12 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
12611269
12621270// EstimateGas returns an estimate of the amount of gas needed to execute the 
12631271// 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 ) {
12651273	bNrOrHash  :=  rpc .BlockNumberOrHashWithNumber (rpc .LatestBlockNumber )
12661274	if  blockNrOrHash  !=  nil  {
12671275		bNrOrHash  =  * blockNrOrHash 
12681276	}
1269- 	return  DoEstimateGas (ctx , s .b , args , bNrOrHash , s .b .RPCGasCap ())
1277+ 	return  DoEstimateGas (ctx , s .b , args , bNrOrHash , overrides ,  s .b .RPCGasCap ())
12701278}
12711279
12721280// RPCMarshalHeader converts the given header to the RPC output . 
0 commit comments