From 5b01306c12c779b691cf500839c7f96102c6f129 Mon Sep 17 00:00:00 2001 From: Mo Lin Date: Thu, 3 Jun 2021 14:17:04 +0800 Subject: [PATCH] add api pos_getEpochGasPoolByBlock --- internal/web3ext/web3ext.go | 5 +++++ pos/posapi/api.go | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 3407bd96..eafbe73a 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -275,6 +275,11 @@ web3._extend({ call: 'pos_getEpochGasPool', params: 1 }), + new web3._extend.Method({ + name: 'getEpochGasPoolByBlock', + call: 'pos_getEpochGasPoolByBlock', + params: 2 + }), new web3._extend.Method({ name: 'getStakerInfo', call: 'pos_getStakerInfo', diff --git a/pos/posapi/api.go b/pos/posapi/api.go index cd973ba1..cbaab8d7 100644 --- a/pos/posapi/api.go +++ b/pos/posapi/api.go @@ -596,6 +596,29 @@ func (a PosApi) GetEpochGasPool(epochID uint64) (string, error) { return incentive.GetEpochGasPool(db, epochID).String(), nil } +func (a PosApi) GetEpochGasPoolByBlock(epochId uint64, blockNr int64) (string, error) { + if !isPosStage() { + return "Not POS stage.", nil + } + + if blockNr > a.chain.CurrentHeader().Number.Int64() { + blockNr = -1 + } + + epID, _ := util.CalEpSlbyTd(a.chain.CurrentHeader().Difficulty.Uint64()) + + if epochId > epID { + return "", errors.New("wrong epochId (It hasn't arrived yet.):" + convert.Uint64ToString(epochId)) + } + + state, _, err := a.backend.StateAndHeaderByNumber(context.Background(), rpc.BlockNumber(blockNr)) + if err != nil { + return "", err + } + + return incentive.GetEpochGasPool(state, epochId).String(), nil +} + func (a PosApi) GetRBAddress(epochID uint64) []common.Address { if !isPosStage() { return nil