Skip to content

Commit

Permalink
feat: add more logs, add configuration via config
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed May 7, 2021
1 parent 19ed4fe commit 2249086
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ var rootCmd = &cobra.Command{
Long: "Tool to monitor missed blocks for Cosmos-chain validators",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if ConfigPath == "" {
log.Trace().Msg("Config file not provided")
return nil
}

log.Trace().Msg("Config file provided")

viper.SetConfigFile(ConfigPath)
if err := viper.ReadInConfig(); err != nil {
log.Info().Err(err).Msg("Error reading config file")
Expand All @@ -62,11 +65,51 @@ var rootCmd = &cobra.Command{
}
})

setBechPrefixes(cmd)

return nil
},
Run: Execute,
}

func setBechPrefixes(cmd *cobra.Command) {
if flag, err := cmd.Flags().GetString("bech-account-prefix"); flag != "" && err == nil {
AccountPrefix = flag
} else {
AccountPrefix = Prefix
}

if flag, err := cmd.Flags().GetString("bech-account-pubkey-prefix"); flag != "" && err == nil {
AccountPubkeyPrefix = flag
} else {
AccountPubkeyPrefix = Prefix + "pub"
}

if flag, err := cmd.Flags().GetString("bech-validator-prefix"); flag != "" && err == nil {
ValidatorPrefix = flag
} else {
ValidatorPrefix = Prefix + "valoper"
}

if flag, err := cmd.Flags().GetString("bech-validator-pubkey-prefix"); flag != "" && err == nil {
ValidatorPubkeyPrefix = flag
} else {
ValidatorPubkeyPrefix = Prefix + "valoperpub"
}

if flag, err := cmd.Flags().GetString("bech-consensus-node-prefix"); flag != "" && err == nil {
ConsensusNodePrefix = flag
} else {
ConsensusNodePrefix = Prefix + "valcons"
}

if flag, err := cmd.Flags().GetString("bech-consensus-node-pubkey-prefix"); flag != "" && err == nil {
ConsensusNodePubkeyPrefix = flag
} else {
ConsensusNodePubkeyPrefix = Prefix + "valconspub"
}
}

func Execute(cmd *cobra.Command, args []string) {
logLevel, err := zerolog.ParseLevel(LogLevel)
if err != nil {
Expand Down Expand Up @@ -124,6 +167,7 @@ func Execute(cmd *cobra.Command, args []string) {
}

func main() {
rootCmd.PersistentFlags().StringVar(&ConfigPath, "config", "", "Config file path")
rootCmd.PersistentFlags().StringVar(&Denom, "denom", "uxprt", "Cosmos coin denom")
rootCmd.PersistentFlags().StringVar(&ListenAddress, "listen-address", ":9300", "The address this exporter would listen on")
rootCmd.PersistentFlags().StringVar(&NodeAddress, "node", "localhost:9090", "RPC node address")
Expand All @@ -132,10 +176,12 @@ func main() {

// some networks, like Iris, have the different prefixes for address, validator and consensus node
rootCmd.PersistentFlags().StringVar(&Prefix, "bech-prefix", "persistence", "Bech32 global prefix")
rootCmd.PersistentFlags().StringVar(&ValidatorPrefix, "bech-validator-prefix", Prefix+"valoper", "Bech32 validator prefix")
rootCmd.PersistentFlags().StringVar(&ValidatorPubkeyPrefix, "bech-validator-pubkey-prefix", Prefix+"valoperpub", "Bech32 pubkey validator prefix")
rootCmd.PersistentFlags().StringVar(&ConsensusNodePrefix, "bech-consensus-node-prefix", Prefix+"valcons", "Bech32 consensus node prefix")
rootCmd.PersistentFlags().StringVar(&ConsensusNodePubkeyPrefix, "bech-consensus-node-pubkey-prefix", Prefix+"valconspub", "Bech32 pubkey consensus node prefix")
rootCmd.PersistentFlags().StringVar(&AccountPrefix, "bech-account-prefix", "", "Bech32 account prefix")
rootCmd.PersistentFlags().StringVar(&AccountPubkeyPrefix, "bech-account-pubkey-prefix", "", "Bech32 pubkey account prefix")
rootCmd.PersistentFlags().StringVar(&ValidatorPrefix, "bech-validator-prefix", "", "Bech32 validator prefix")
rootCmd.PersistentFlags().StringVar(&ValidatorPubkeyPrefix, "bech-validator-pubkey-prefix", "", "Bech32 pubkey validator prefix")
rootCmd.PersistentFlags().StringVar(&ConsensusNodePrefix, "bech-consensus-node-prefix", "", "Bech32 consensus node prefix")
rootCmd.PersistentFlags().StringVar(&ConsensusNodePubkeyPrefix, "bech-consensus-node-pubkey-prefix", "", "Bech32 pubkey consensus node prefix")

if err := rootCmd.Execute(); err != nil {
log.Fatal().Err(err).Msg("Could not start application")
Expand Down

0 comments on commit 2249086

Please sign in to comment.