From 1c7899df35df41a422142da523a4f1ec31ad8e4d Mon Sep 17 00:00:00 2001 From: linhaiyang <1183679527@qq.com> Date: Fri, 6 Aug 2021 15:43:55 +0800 Subject: [PATCH] ethapi add basefee --- eth/api.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/eth/api.go b/eth/api.go index 8b96d1f316..11bfd21195 100644 --- a/eth/api.go +++ b/eth/api.go @@ -30,6 +30,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/consensus/misc" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/state" @@ -56,6 +57,15 @@ func (api *PublicEthereumAPI) Etherbase() (common.Address, error) { return api.e.Etherbase() } +// BaseFee for rpc +func (api *PublicEthereumAPI) BaseFee(ctx context.Context) (*big.Int, error) { + header, err := api.e.APIBackend.HeaderByNumber(ctx, rpc.LatestBlockNumber) + if err != nil { + return nil, err + } + return misc.CalcBaseFee(api.e.APIBackend.ChainConfig(), header), nil +} + // Coinbase is the address that mining rewards will be send to (alias for Etherbase) func (api *PublicEthereumAPI) Coinbase() (common.Address, error) { return api.Etherbase()