Skip to content
Merged
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
30 changes: 16 additions & 14 deletions ocp/rpc/currency/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,22 +370,24 @@ func (s *currencyServer) GetHistoricalMintData(ctx context.Context, req *currenc
// if it's newer than the last historical point
latestTime := getLatestHistoricalTime()
if len(data) == 0 || data[len(data)-1].Timestamp.AsTime().Before(latestTime) {
latestReserve, err := s.data.GetCurrencyReserveAtTime(ctx, mintAccount.PublicKey().ToBase58(), latestTime)
if err != nil {
log.With(zap.Error(err)).Warn("failed to load latest currency reserve")
return nil, status.Error(codes.Internal, "")
}
func() {
latestReserve, err := s.data.GetCurrencyReserveAtTime(ctx, mintAccount.PublicKey().ToBase58(), latestTime)
if err != nil {
log.With(zap.Error(err)).Warn("failed to load latest currency reserve")
return
}

latestExchangeRate, err := s.data.GetExchangeRate(ctx, currencyCode, latestTime)
if err != nil {
log.With(zap.Error(err)).Warn("failed to load latest exchange rate")
return nil, status.Error(codes.Internal, "")
}
latestExchangeRate, err := s.data.GetExchangeRate(ctx, currencyCode, latestTime)
if err != nil {
log.With(zap.Error(err)).Warn("failed to load latest exchange rate")
return
}

data = append(data, &currencypb.HistoricalMintData{
Timestamp: timestamppb.New(latestTime),
MarketCap: calculateMarketCap(latestReserve.SupplyFromBonding, latestExchangeRate.Rate),
})
data = append(data, &currencypb.HistoricalMintData{
Timestamp: timestamppb.New(latestTime),
MarketCap: calculateMarketCap(latestReserve.SupplyFromBonding, latestExchangeRate.Rate),
})
}()
}

if len(data) == 0 {
Expand Down