From 5135d1e7573e7ba9a3f8acac1f6cca16bd2edf05 Mon Sep 17 00:00:00 2001 From: Matthew Slipper Date: Tue, 28 Aug 2018 01:08:16 -0700 Subject: [PATCH 1/4] Add show-address command Closes #1274. --- server/tm_cmds.go | 49 +++++++++++++++++++++++++++++++++++------------ server/util.go | 1 + 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/server/tm_cmds.go b/server/tm_cmds.go index c2395e3996eb..efb697a72f15 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 printCryptoWire(valPubKey) } pubkey, err := sdk.Bech32ifyValPub(valPubKey) if err != nil { @@ -61,10 +53,43 @@ 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 } +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 printCryptoWire(valAddr) + } + + fmt.Println(valAddr.String()) + return nil + }, + } + + cmd.Flags().Bool(client.FlagJson, false, "get machine parseable output") + return cmd +} + +func printCryptoWire(data interface{}) error { + cdc := wire.NewCodec() + wire.RegisterCrypto(cdc) + marshalled, err := cdc.MarshalJSON(data) + 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( From e6b1605649b9a91e1262ea8e8786eb6aa2239cdd Mon Sep 17 00:00:00 2001 From: Matthew Slipper Date: Tue, 28 Aug 2018 01:09:40 -0700 Subject: [PATCH 2/4] Add PENDING entry --- PENDING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/PENDING.md b/PENDING.md index f45541ccdc19..63107a41041a 100644 --- a/PENDING.md +++ b/PENDING.md @@ -41,6 +41,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 From c73933448f80875c5c2c31a3a874732603a184a2 Mon Sep 17 00:00:00 2001 From: Matthew Slipper Date: Tue, 28 Aug 2018 01:10:21 -0700 Subject: [PATCH 3/4] Add godoc --- server/tm_cmds.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/tm_cmds.go b/server/tm_cmds.go index efb697a72f15..2eba6a4055df 100644 --- a/server/tm_cmds.go +++ b/server/tm_cmds.go @@ -57,6 +57,7 @@ func ShowValidatorCmd(ctx *Context) *cobra.Command { return &cmd } +// ShowAddressCmd - show this node's validator address func ShowAddressCmd(ctx *Context) *cobra.Command { cmd := &cobra.Command{ Use: "show-address", From 6f8a6dee6128481c7de7596f126ea3705795b684 Mon Sep 17 00:00:00 2001 From: Matthew Slipper Date: Thu, 30 Aug 2018 01:04:25 -0700 Subject: [PATCH 4/4] Updates from code review --- server/tm_cmds.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/tm_cmds.go b/server/tm_cmds.go index 2eba6a4055df..d84022183ae1 100644 --- a/server/tm_cmds.go +++ b/server/tm_cmds.go @@ -43,7 +43,7 @@ func ShowValidatorCmd(ctx *Context) *cobra.Command { valPubKey := privValidator.PubKey if viper.GetBool(client.FlagJson) { - return printCryptoWire(valPubKey) + return printlnJSON(valPubKey) } pubkey, err := sdk.Bech32ifyValPub(valPubKey) if err != nil { @@ -68,7 +68,7 @@ func ShowAddressCmd(ctx *Context) *cobra.Command { valAddr := (sdk.ValAddress)(privValidator.Address) if viper.GetBool(client.FlagJson) { - return printCryptoWire(valAddr) + return printlnJSON(valAddr) } fmt.Println(valAddr.String()) @@ -80,10 +80,10 @@ func ShowAddressCmd(ctx *Context) *cobra.Command { return cmd } -func printCryptoWire(data interface{}) error { +func printlnJSON(v interface{}) error { cdc := wire.NewCodec() wire.RegisterCrypto(cdc) - marshalled, err := cdc.MarshalJSON(data) + marshalled, err := cdc.MarshalJSON(v) if err != nil { return err }