Skip to content

Commit

Permalink
fix: json decoding of coingecko prices
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yang committed Jul 30, 2023
1 parent 791bdbb commit c407b55
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions feeder/priceprovider/sources/coingecko.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package sources

import (
json2 "encoding/json"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"

"github.com/NibiruChain/nibiru/x/common/set"
"github.com/NibiruChain/pricefeeder/types"
"github.com/tendermint/tendermint/libs/json"
)

const (
Expand All @@ -20,16 +19,16 @@ const (
)

type CoingeckoTicker struct {
Price float64 `json:"usd,string"`
Price float64 `json:"usd"`
}

type CoingeckoConfig struct {
ApiKey string `json:"api_key"`
}

func CoingeckoPriceUpdate(jsonConfig json2.RawMessage) types.FetchPricesFunc {
func CoingeckoPriceUpdate(sourceConfig json.RawMessage) types.FetchPricesFunc {
return func(symbols set.Set[types.Symbol]) (map[types.Symbol]float64, error) {
c, err := extractConfig(jsonConfig)
c, err := extractConfig(sourceConfig)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -57,7 +56,7 @@ func CoingeckoPriceUpdate(jsonConfig json2.RawMessage) types.FetchPricesFunc {
}

// extractConfig tries to get the configuration, if nothing is found, it returns an empty config.
func extractConfig(jsonConfig json2.RawMessage) (*CoingeckoConfig, error) {
func extractConfig(jsonConfig json.RawMessage) (*CoingeckoConfig, error) {
c := &CoingeckoConfig{}
if len(jsonConfig) > 0 {
err := json.Unmarshal(jsonConfig, c)
Expand Down

0 comments on commit c407b55

Please sign in to comment.