From 139242230b9303a3c07f0b33c78a8fa10ae00bf2 Mon Sep 17 00:00:00 2001 From: Sergey <83376337+freak12techno@users.noreply.github.com> Date: Sun, 19 May 2024 06:01:19 +0300 Subject: [PATCH] feat: add rpc-host as first argument (#22) --- README.md | 8 ++++---- cmd/tmtop.go | 14 ++++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a05bc9e..787d3f0 100644 --- a/README.md +++ b/README.md @@ -51,26 +51,26 @@ Then just run it: To run it for a sovereign Cosmos-based chain, something like this should be enough: ``` -./tmtop --rpc-host +./tmtop ``` To run it for a sovereign chain that is not Cosmos-based (for example, Nomic), something like this should be enough (this will limit the app possibilities, as in, it won't display validators monikers, upgrades status etc.): ``` -./tmtop --rpc-host --chain-type tendermint +./tmtop --chain-type tendermint ``` If a chain is not Cosmos-based, but exposes a webserver that is compatible with LCD REST API of cosmos-sdk, you can try running it this way to fetch data from LCD (the `--lcd-host` parameter is not used in other cases): ``` -./tmtop --rpc-host --chain-type cosmos-lcd --lcd-host +./tmtop --chain-type cosmos-lcd --lcd-host ``` To run it for a Cosmos-based consumer chains (like Stride or Neutron), something like this should be enough: ``` -./tmtop --rpc-host --provider-rpc-host --consumer-chain-id +./tmtop --provider-rpc-host --consumer-chain-id ``` There are more parameters to tweak, for all the possible arguments, see `./tmtop --help`. diff --git a/cmd/tmtop.go b/cmd/tmtop.go index 102cb52..fc075cd 100644 --- a/cmd/tmtop.go +++ b/cmd/tmtop.go @@ -13,7 +13,13 @@ var ( version = "unknown" ) -func Execute(config configPkg.Config) { +func Execute(config configPkg.Config, args []string) { + if len(args) == 0 || args[0] == "" { + config.RPCHost = "http://localhost:26657" + } else { + config.RPCHost = args[0] + } + app := pkg.NewApp(config, version) app.Start() } @@ -22,18 +28,18 @@ func main() { var config configPkg.Config rootCmd := &cobra.Command{ - Use: "tmtop", + Use: "tmtop [RPC host URL]", Long: "Observe the pre-voting status of any Tendermint-based blockchain.", Version: version, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { return config.Validate() }, + Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - Execute(config) + Execute(config, args) }, } - rootCmd.PersistentFlags().StringVar(&config.RPCHost, "rpc-host", "http://localhost:26657", "RPC host URL") rootCmd.PersistentFlags().StringVar(&config.ProviderRPCHost, "provider-rpc-host", "", "Provider chain RPC host URL") rootCmd.PersistentFlags().StringVar(&config.ConsumerChainID, "consumer-chain-id", "", "Consumer chain ID") rootCmd.PersistentFlags().DurationVar(&config.RefreshRate, "refresh-rate", time.Second, "Refresh rate")