From 7c681429cea77e1c08eedab4c9f87a8ae9165066 Mon Sep 17 00:00:00 2001 From: Alvaro Revuelta Date: Mon, 5 Dec 2022 19:44:48 +0100 Subject: [PATCH] Add gnosis price (#39) --- config/config.go | 9 +++++++-- price/price.go | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index b3ac02c..b9bfd55 100644 --- a/config/config.go +++ b/config/config.go @@ -16,6 +16,8 @@ var ReleaseVersion = "custom-build" // 16 Gnosis mainnet var SlotsInEpoch = uint64(32) +var Network = "" + type Config struct { PoolNames []string Network string @@ -80,6 +82,9 @@ func NewCliConfig() (*Config, error) { if *network == "gnosis" { SlotsInEpoch = uint64(16) } + + // Used for the price + Network = *network /* if *poolName == "required" { log.Fatal("pool-name flag is required") @@ -98,7 +103,7 @@ func NewCliConfig() (*Config, error) { }*/ conf := &Config{ - PoolNames: poolNames, + PoolNames: poolNames, Network: *network, BeaconRpcEndpoint: *beaconRpcEndpoint, PrometheusPort: *prometheusPort, @@ -127,6 +132,6 @@ func logConfig(cfg *Config) { "Eth1Address": cfg.Eth1Address, "Eth2Address": cfg.Eth2Address, "EpochDebug": cfg.EpochDebug, - "SlotsInEpoch": SlotsInEpoch, + "SlotsInEpoch": SlotsInEpoch, }).Info("Cli Config:") } diff --git a/price/price.go b/price/price.go index 9af1f35..361a6f3 100644 --- a/price/price.go +++ b/price/price.go @@ -3,6 +3,7 @@ package price import ( "time" + "github.com/alrevuelta/eth-pools-metrics/config" "github.com/alrevuelta/eth-pools-metrics/postgresql" "github.com/alrevuelta/eth-pools-metrics/prometheus" "github.com/pkg/errors" @@ -10,7 +11,6 @@ import ( gecko "github.com/superoo7/go-gecko/v3" ) -var ids = []string{"ethereum"} var vc = []string{"usd", "eurr"} type Price struct { @@ -42,12 +42,21 @@ func NewPrice(postgresEndpoint string) (*Price, error) { } func (p *Price) GetEthPrice() { - sp, err := p.coingecko.SimplePrice(ids, vc) + id := "" + if config.Network == "mainnet" { + id = "ethereum" + } else if config.Network == "gnosis" { + id = "gnosis" + } else { + log.Fatal("Network not supported: ", config.Network) + } + + sp, err := p.coingecko.SimplePrice([]string{id}, vc) if err != nil { log.Error(err) } - eth := (*sp)["ethereum"] + eth := (*sp)[id] ethPriceUsd := eth["usd"] logPrice(ethPriceUsd)