diff --git a/PENDING.md b/PENDING.md index 339868c99def..14747be9d62e 100644 --- a/PENDING.md +++ b/PENDING.md @@ -42,6 +42,7 @@ FEATURES * [cli] \#2047 The --gas-adjustment flag can be used to adjust the estimate obtained via the simulation triggered by --gas=0. * Gaia + * [cli] #2170 added ability to show the node's address via `gaiad tendermint show-address` * SDK * [querier] added custom querier functionality, so ABCI query requests can be handled by keepers diff --git a/server/tm_cmds.go b/server/tm_cmds.go index c2395e3996eb..d84022183ae1 100644 --- a/server/tm_cmds.go +++ b/server/tm_cmds.go @@ -11,6 +11,7 @@ import ( tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" "github.com/tendermint/tendermint/p2p" pvm "github.com/tendermint/tendermint/privval" + "github.com/cosmos/cosmos-sdk/client" ) // ShowNodeIDCmd - ported from Tendermint, dump node ID to stdout @@ -32,7 +33,6 @@ func ShowNodeIDCmd(ctx *Context) *cobra.Command { // ShowValidator - ported from Tendermint, show this node's validator info func ShowValidatorCmd(ctx *Context) *cobra.Command { - flagJSON := "json" cmd := cobra.Command{ Use: "show-validator", Short: "Show this node's tendermint validator info", @@ -42,16 +42,8 @@ func ShowValidatorCmd(ctx *Context) *cobra.Command { privValidator := pvm.LoadOrGenFilePV(cfg.PrivValidatorFile()) valPubKey := privValidator.PubKey - if viper.GetBool(flagJSON) { - - cdc := wire.NewCodec() - wire.RegisterCrypto(cdc) - pubKeyJSONBytes, err := cdc.MarshalJSON(valPubKey) - if err != nil { - return err - } - fmt.Println(string(pubKeyJSONBytes)) - return nil + if viper.GetBool(client.FlagJson) { + return printlnJSON(valPubKey) } pubkey, err := sdk.Bech32ifyValPub(valPubKey) if err != nil { @@ -61,10 +53,44 @@ func ShowValidatorCmd(ctx *Context) *cobra.Command { return nil }, } - cmd.Flags().Bool(flagJSON, false, "get machine parseable output") + cmd.Flags().Bool(client.FlagJson, false, "get machine parseable output") return &cmd } +// ShowAddressCmd - show this node's validator address +func ShowAddressCmd(ctx *Context) *cobra.Command { + cmd := &cobra.Command{ + Use: "show-address", + Short: "Shows this node's tendermint validator address", + RunE: func(cmd *cobra.Command, args []string) error { + cfg := ctx.Config + privValidator := pvm.LoadOrGenFilePV(cfg.PrivValidatorFile()) + valAddr := (sdk.ValAddress)(privValidator.Address) + + if viper.GetBool(client.FlagJson) { + return printlnJSON(valAddr) + } + + fmt.Println(valAddr.String()) + return nil + }, + } + + cmd.Flags().Bool(client.FlagJson, false, "get machine parseable output") + return cmd +} + +func printlnJSON(v interface{}) error { + cdc := wire.NewCodec() + wire.RegisterCrypto(cdc) + marshalled, err := cdc.MarshalJSON(v) + if err != nil { + return err + } + fmt.Println(string(marshalled)) + return nil +} + // UnsafeResetAllCmd - extension of the tendermint command, resets initialization func UnsafeResetAllCmd(ctx *Context) *cobra.Command { return &cobra.Command{ diff --git a/server/util.go b/server/util.go index 0f5a7b3eb2ba..04c539eb4220 100644 --- a/server/util.go +++ b/server/util.go @@ -112,6 +112,7 @@ func AddCommands( tendermintCmd.AddCommand( ShowNodeIDCmd(ctx), ShowValidatorCmd(ctx), + ShowAddressCmd(ctx), ) rootCmd.AddCommand(