eth/gasprice: implement feeHistory API (#23033)
* eth/gasprice: implement feeHistory API * eth/gasprice: factored out resolveBlockRange * eth/gasprice: add sanity check for missing block * eth/gasprice: fetch actual gas used from receipts * miner, eth/gasprice: add PendingBlockAndReceipts * internal/ethapi: use hexutil.Big * eth/gasprice: return error when requesting beyond head block * eth/gasprice: fixed tests and return errors correctly * eth/gasprice: rename receiver name * eth/gasprice: return directly if blockCount == 0 Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
This commit is contained in:
@ -60,7 +60,10 @@ func (b *LesApiBackend) SetHead(number uint64) {
|
||||
}
|
||||
|
||||
func (b *LesApiBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) {
|
||||
if number == rpc.LatestBlockNumber || number == rpc.PendingBlockNumber {
|
||||
if number == rpc.PendingBlockNumber {
|
||||
return nil, nil
|
||||
}
|
||||
if number == rpc.LatestBlockNumber {
|
||||
return b.eth.blockchain.CurrentHeader(), nil
|
||||
}
|
||||
return b.eth.blockchain.GetHeaderByNumberOdr(ctx, uint64(number))
|
||||
@ -122,6 +125,10 @@ func (b *LesApiBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash r
|
||||
return nil, errors.New("invalid arguments; neither block nor hash specified")
|
||||
}
|
||||
|
||||
func (b *LesApiBackend) PendingBlockAndReceipts() (*types.Block, types.Receipts) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (b *LesApiBackend) StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error) {
|
||||
header, err := b.HeaderByNumber(ctx, number)
|
||||
if err != nil {
|
||||
@ -255,6 +262,10 @@ func (b *LesApiBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error)
|
||||
return b.gpo.SuggestTipCap(ctx)
|
||||
}
|
||||
|
||||
func (b *LesApiBackend) FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (firstBlock rpc.BlockNumber, reward [][]*big.Int, baseFee []*big.Int, gasUsedRatio []float64, err error) {
|
||||
return b.gpo.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
|
||||
}
|
||||
|
||||
func (b *LesApiBackend) ChainDb() ethdb.Database {
|
||||
return b.eth.chainDb
|
||||
}
|
||||
|
Reference in New Issue
Block a user