From 670bfdedbef1b9f24d6ec37d2c5f3c320a33eb43 Mon Sep 17 00:00:00 2001 From: tbjump Date: Wed, 3 May 2023 23:23:44 +0000 Subject: [PATCH] node/governor: add type assertion in queryCoinGecko --- node/pkg/governor/governor_prices.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/node/pkg/governor/governor_prices.go b/node/pkg/governor/governor_prices.go index 49ac924d5..1778cd70e 100644 --- a/node/pkg/governor/governor_prices.go +++ b/node/pkg/governor/governor_prices.go @@ -155,11 +155,19 @@ func (gov *ChainGovernor) queryCoinGecko() error { cge, exists := gov.tokensByCoinGeckoId[coinGeckoId] if exists { // If a price is not set in CoinGecko, they return an empty entry. Treat that as a zero price. - price := float64(0) + var price float64 + m := data.(map[string]interface{}) if len(m) != 0 { var ok bool - price, ok = m["usd"].(float64) + price_, ok := m["usd"] + if !ok { + gov.logger.Error("failed to parse CoinGecko response, reverting to configured price for this token", zap.String("coinGeckoId", coinGeckoId)) + // By continuing, we leave this one in the local map so the price will get reverted below. + continue + } + + price, ok = price_.(float64) if !ok { gov.logger.Error("failed to parse CoinGecko response, reverting to configured price for this token", zap.String("coinGeckoId", coinGeckoId)) // By continuing, we leave this one in the local map so the price will get reverted below.