|
|
@ -1134,7 +1134,7 @@ func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrO |
|
|
|
return result.Return(), result.Err |
|
|
|
return result.Return(), result.Err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, gasCap uint64) (hexutil.Uint64, error) { |
|
|
|
func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, gasCap uint64) (hexutil.Uint64, error) { |
|
|
|
// Binary search the gas requirement, as it may be higher than the amount used
|
|
|
|
// Binary search the gas requirement, as it may be higher than the amount used
|
|
|
|
var ( |
|
|
|
var ( |
|
|
|
lo uint64 = params.TxGas - 1 |
|
|
|
lo uint64 = params.TxGas - 1 |
|
|
@ -1176,6 +1176,10 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
err = overrides.Apply(state) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return 0, err |
|
|
|
|
|
|
|
} |
|
|
|
balance := state.GetBalance(*args.From) // from can't be nil
|
|
|
|
balance := state.GetBalance(*args.From) // from can't be nil
|
|
|
|
available := new(big.Int).Set(balance) |
|
|
|
available := new(big.Int).Set(balance) |
|
|
|
if args.Value != nil { |
|
|
|
if args.Value != nil { |
|
|
@ -1221,6 +1225,10 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr |
|
|
|
if state == nil || err != nil { |
|
|
|
if state == nil || err != nil { |
|
|
|
return 0, err |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
err = overrides.Apply(state) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return 0, err |
|
|
|
|
|
|
|
} |
|
|
|
// Execute the binary search and hone in on an executable gas limit
|
|
|
|
// Execute the binary search and hone in on an executable gas limit
|
|
|
|
for lo+1 < hi { |
|
|
|
for lo+1 < hi { |
|
|
|
s := state.Copy() |
|
|
|
s := state.Copy() |
|
|
@ -1261,12 +1269,12 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr |
|
|
|
|
|
|
|
|
|
|
|
// EstimateGas returns an estimate of the amount of gas needed to execute the
|
|
|
|
// EstimateGas returns an estimate of the amount of gas needed to execute the
|
|
|
|
// given transaction against the current pending block.
|
|
|
|
// given transaction against the current pending block.
|
|
|
|
func (s *BlockChainAPI) EstimateGas(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error) { |
|
|
|
func (s *BlockChainAPI) EstimateGas(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash, overrides *StateOverride) (hexutil.Uint64, error) { |
|
|
|
bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber) |
|
|
|
bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber) |
|
|
|
if blockNrOrHash != nil { |
|
|
|
if blockNrOrHash != nil { |
|
|
|
bNrOrHash = *blockNrOrHash |
|
|
|
bNrOrHash = *blockNrOrHash |
|
|
|
} |
|
|
|
} |
|
|
|
return DoEstimateGas(ctx, s.b, args, bNrOrHash, s.b.RPCGasCap()) |
|
|
|
return DoEstimateGas(ctx, s.b, args, bNrOrHash, overrides, s.b.RPCGasCap()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// RPCMarshalHeader converts the given header to the RPC output .
|
|
|
|
// RPCMarshalHeader converts the given header to the RPC output .
|
|
|
|