Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2656,18 +2656,18 @@ type tokenSupply struct {
BlockNumber *hexutil.Big `json:"blockNumber"`
}

func (s *BlockChainAPI) GetTokenStats(ctx context.Context, epochNr rpc.EpochNumber) (*tokenSupply, error) {
engine, ok := s.b.Engine().(*XDPoS.XDPoS)
func (api *BlockChainAPI) GetTokenStats(ctx context.Context, epochNr rpc.EpochNumber) (*tokenSupply, error) {
engine, ok := api.b.Engine().(*XDPoS.XDPoS)
if !ok {
return nil, errors.New("undefined XDPoS consensus engine")
}
statedb, header, err := s.b.StateAndHeaderByNumber(ctx, rpc.LatestBlockNumber)
statedb, header, err := api.b.StateAndHeaderByNumber(ctx, rpc.LatestBlockNumber)
nonce := statedb.GetNonce(common.MintedRecordAddressBinary)
if nonce == 0 {
return nil, errors.New("mintedRecordAddress is not initialized due to Reward Upgrade is not applied")
}
currentRound, err := engine.EngineV2.GetRoundNumber(header)
currentEpoch := s.b.ChainConfig().XDPoS.V2.SwitchEpoch + uint64(currentRound)/s.b.ChainConfig().XDPoS.Epoch
currentEpoch := api.b.ChainConfig().XDPoS.V2.SwitchEpoch + uint64(currentRound)/api.b.ChainConfig().XDPoS.Epoch
if err != nil {
return nil, err
}
Expand All @@ -2686,11 +2686,11 @@ func (s *BlockChainAPI) GetTokenStats(ctx context.Context, epochNr rpc.EpochNumb
}
postMinted := statedb.GetPostMinted(epochNum).Big()
number := statedb.GetPostRewardBlock(epochNum).Big()
targetHeader, err := s.b.HeaderByNumber(ctx, rpc.BlockNumber(number.Int64()))
targetHeader, err := api.b.HeaderByNumber(ctx, rpc.BlockNumber(number.Int64()))
if err != nil {
return nil, err
}
config := s.b.ChainConfig().XDPoS
config := api.b.ChainConfig().XDPoS
if config == nil {
return nil, errors.New("xdpos config is nil")
}
Expand Down