Skip to content

Commit 98404db

Browse files
authored
Improve closest FX rate logic for historical mint data (#166)
1 parent 532ce2e commit 98404db

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

ocp/rpc/currency/historical_data.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,15 @@ func (s *currencyServer) getCachedExchangeRateHistory(
259259

260260
// findClosestExchangeRate finds the exchange rate closest to the given time.
261261
func findClosestExchangeRate(t time.Time, history []*currency.ExchangeRateRecord) (float64, bool) {
262-
// Find the closest preceding exchange rate
262+
// Find the closest exchange rate
263263
var closestRate float64
264264
var found bool
265265
for _, record := range history {
266266
if record.Time.After(t) {
267+
if !found {
268+
closestRate = record.Rate
269+
found = true
270+
}
267271
break
268272
}
269273
closestRate = record.Rate

0 commit comments

Comments
 (0)