Skip to content

Commit

Permalink
feat: add price as a command line option. (mainly for testnets)
Browse files Browse the repository at this point in the history
  • Loading branch information
PFC-developer committed Oct 10, 2023
1 parent d957562 commit 97128ca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ You can pass the arguments to the executable file to configure it. Here is the p
- `--log-devel` - logger level. Defaults to `info`. You can set it to `debug` to make it more verbose.
- `--limit` - pagination limit for gRPC requests. Defaults to 1000.
- `--json` - output logs as JSON. Useful if you don't read it on servers but instead use logging aggregation solutions such as ELK stack.
- `--price` - fetch token price (defaults to true)


You can also specify custom Bech32 prefixes for wallets, validators, consensus nodes, and their pubkeys by using the following params:
Expand Down
24 changes: 13 additions & 11 deletions general.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,20 @@ func NewGeneralMetrics(reg prometheus.Registerer) *GeneralMetrics {

}
func getGeneralMetrics(wg *sync.WaitGroup, sublogger *zerolog.Logger, metrics *GeneralMetrics, s *service) {
wg.Add(1)
go func() {
defer wg.Done()
chain, err := cosmosdirectory.GetChainByChainID(ChainID)
if err != nil {
sublogger.Error().Err(err).Msg("Could not get chain information")
return
}
if TokenPrice {
wg.Add(1)
go func() {
defer wg.Done()
chain, err := cosmosdirectory.GetChainByChainID(ChainID)
if err != nil {
sublogger.Error().Err(err).Msg("Could not get chain information")
return
}

price := chain.GetPriceUSD()
metrics.tokenPrice.Set(price)
}()
price := chain.GetPriceUSD()
metrics.tokenPrice.Set(price)
}()
}

wg.Add(1)
go func() {
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (
Upgrades bool
Proposals bool
Params bool
TokenPrice bool
)

type service struct {
Expand Down Expand Up @@ -207,6 +208,7 @@ func Execute(_ *cobra.Command, _ []string) {
Str("--proposals", fmt.Sprintf("%t", Proposals)).
Str("--params", fmt.Sprintf("%t", Params)).
Str("--upgrades", fmt.Sprintf("%t", Upgrades)).
Str("--price", fmt.Sprintf("%t", TokenPrice)).
Msg("Started with following parameters")

config := sdk.GetConfig()
Expand Down Expand Up @@ -381,6 +383,7 @@ func main() {
rootCmd.PersistentFlags().BoolVar(&Upgrades, "upgrades", false, "serve upgrade info in the single call to /metrics")
rootCmd.PersistentFlags().BoolVar(&Proposals, "proposals", false, "serve active proposal info in the single call to /metrics")
rootCmd.PersistentFlags().BoolVar(&Params, "params", false, "serve chain params info in the single call to /metrics")
rootCmd.PersistentFlags().BoolVar(&TokenPrice, "price", true, "fetch token price")
rootCmd.PersistentFlags().StringSliceVar(&Wallets, "wallets", nil, "serve info about passed wallets")
rootCmd.PersistentFlags().StringSliceVar(&Validators, "validators", nil, "serve info about passed validators")

Expand Down

0 comments on commit 97128ca

Please sign in to comment.