Skip to content

Commit

Permalink
Bugfix: QiRateAtBlock and QuaiRateAtBlock should allow for latest blo…
Browse files Browse the repository at this point in the history
…ck selection
  • Loading branch information
jdowning100 committed Oct 18, 2024
1 parent bbc1bac commit 99d786d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions internal/quaiapi/quai_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,11 @@ func (s *PublicBlockChainQuaiAPI) QiRateAtBlock(ctx context.Context, blockNrOrHa
var header *types.WorkObject
var err error
if blockNr, ok := blockNrOrHash.Number(); ok {
header, err = s.b.HeaderByNumber(ctx, rpc.BlockNumber(blockNr))
if blockNr == rpc.LatestBlockNumber {
header = s.b.CurrentHeader()
} else {
header, err = s.b.HeaderByNumber(ctx, rpc.BlockNumber(blockNr))
}
} else if hash, ok := blockNrOrHash.Hash(); ok {
header, err = s.b.HeaderByHash(ctx, hash)
} else {
Expand All @@ -821,6 +825,8 @@ func (s *PublicBlockChainQuaiAPI) QiRateAtBlock(ctx context.Context, blockNrOrHa
if err != nil {
s.b.Logger().WithField("err", err).Error("Error calculating QiRateAtBlock")
return nil
} else if header == nil {
return nil
}
return (*hexutil.Big)(misc.QiToQuai(header, new(big.Int).SetUint64(qiAmount)))
}
Expand All @@ -830,7 +836,11 @@ func (s *PublicBlockChainQuaiAPI) QuaiRateAtBlock(ctx context.Context, blockNrOr
var header *types.WorkObject
var err error
if blockNr, ok := blockNrOrHash.Number(); ok {
header, err = s.b.HeaderByNumber(ctx, rpc.BlockNumber(blockNr))
if blockNr == rpc.LatestBlockNumber {
header = s.b.CurrentHeader()
} else {
header, err = s.b.HeaderByNumber(ctx, rpc.BlockNumber(blockNr))
}
} else if hash, ok := blockNrOrHash.Hash(); ok {
header, err = s.b.HeaderByHash(ctx, hash)
} else {
Expand All @@ -839,6 +849,8 @@ func (s *PublicBlockChainQuaiAPI) QuaiRateAtBlock(ctx context.Context, blockNrOr
if err != nil {
s.b.Logger().WithField("err", err).Error("Error calculating QuaiRateAtBlock")
return nil
} else if header == nil {
return nil
}
return (*hexutil.Big)(misc.QuaiToQi(header, new(big.Int).SetUint64(quaiAmount)))
}
Expand Down

0 comments on commit 99d786d

Please sign in to comment.