Skip to content

Commit

Permalink
add api pos_getEpochGasPoolByBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
lolieatcat committed Jun 3, 2021
1 parent ccf53fb commit 5b01306
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
23 changes: 23 additions & 0 deletions pos/posapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5b01306

Please sign in to comment.