mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
Merge pull request #35 from sei-protocol/multi-estimate
Add DoEstimateGasAfterCalls
This commit is contained in:
commit
da7da77412
1 changed files with 39 additions and 0 deletions
|
|
@ -1219,6 +1219,45 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
|
|||
return hexutil.Uint64(estimate), nil
|
||||
}
|
||||
|
||||
func DoEstimateGasAfterCalls(ctx context.Context, b Backend, args TransactionArgs, calls []TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, timeout time.Duration, gasCap uint64) (hexutil.Uint64, error) {
|
||||
state, header, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
|
||||
if state == nil || err != nil {
|
||||
return 0, err
|
||||
}
|
||||
for _, call := range calls {
|
||||
_, err = doCall(ctx, b, call, state, header, overrides, nil, timeout, gasCap)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
overrides = nil
|
||||
}
|
||||
// Construct the gas estimator option from the user input
|
||||
opts := &gasestimator.Options{
|
||||
Config: b.ChainConfig(),
|
||||
Chain: NewChainContext(ctx, b),
|
||||
Header: header,
|
||||
State: state,
|
||||
ErrorRatio: estimateGasErrorRatio,
|
||||
}
|
||||
|
||||
if err := args.CallDefaults(gasCap, header.BaseFee, b.ChainConfig().ChainID); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
call := args.ToMessage(header.BaseFee)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
// Run the gas estimation andwrap any revertals into a custom return
|
||||
estimate, revert, err := gasestimator.Estimate(ctx, call, opts, gasCap)
|
||||
if err != nil {
|
||||
if len(revert) > 0 {
|
||||
return 0, newRevertError(revert)
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return hexutil.Uint64(estimate), nil
|
||||
}
|
||||
|
||||
// EstimateGas returns the lowest possible gas limit that allows the transaction to run
|
||||
// successfully at block `blockNrOrHash`, or the latest block if `blockNrOrHash` is unspecified. It
|
||||
// returns error if the transaction would revert or if there are unexpected failures. The returned
|
||||
|
|
|
|||
Loading…
Reference in a new issue