|
|
|
@ -505,6 +505,38 @@ func (ec *Client) SuggestGasTipCap(ctx context.Context) (*big.Int, error) { |
|
|
|
|
return (*big.Int)(&hex), nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type feeHistoryResultMarshaling struct { |
|
|
|
|
OldestBlock *hexutil.Big `json:"oldestBlock"` |
|
|
|
|
Reward [][]*hexutil.Big `json:"reward,omitempty"` |
|
|
|
|
BaseFee []*hexutil.Big `json:"baseFeePerGas,omitempty"` |
|
|
|
|
GasUsedRatio []float64 `json:"gasUsedRatio"` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// FeeHistory retrieves the fee market history.
|
|
|
|
|
func (ec *Client) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error) { |
|
|
|
|
var res feeHistoryResultMarshaling |
|
|
|
|
if err := ec.c.CallContext(ctx, &res, "eth_feeHistory", hexutil.Uint(blockCount), toBlockNumArg(lastBlock), rewardPercentiles); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
reward := make([][]*big.Int, len(res.Reward)) |
|
|
|
|
for i, r := range res.Reward { |
|
|
|
|
reward[i] = make([]*big.Int, len(r)) |
|
|
|
|
for j, r := range r { |
|
|
|
|
reward[i][j] = (*big.Int)(r) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
baseFee := make([]*big.Int, len(res.BaseFee)) |
|
|
|
|
for i, b := range res.BaseFee { |
|
|
|
|
baseFee[i] = (*big.Int)(b) |
|
|
|
|
} |
|
|
|
|
return ðereum.FeeHistory{ |
|
|
|
|
OldestBlock: (*big.Int)(res.OldestBlock), |
|
|
|
|
Reward: reward, |
|
|
|
|
BaseFee: baseFee, |
|
|
|
|
GasUsedRatio: res.GasUsedRatio, |
|
|
|
|
}, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// EstimateGas tries to estimate the gas needed to execute a specific transaction based on
|
|
|
|
|
// the current pending state of the backend blockchain. There is no guarantee that this is
|
|
|
|
|
// the true gas limit requirement as other transactions may be added or removed by miners,
|
|
|
|
|