Skip to content

Commit

Permalink
Merge PR #2170: Add show-address command
Browse files Browse the repository at this point in the history
* Add show-address command

Closes #1274.

* Add PENDING entry

* Add godoc

* Updates from code review
  • Loading branch information
mslipper authored and rigelrozanski committed Aug 31, 2018
1 parent 03c56fc commit dc0f132
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 38 additions & 12 deletions server/tm_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -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 {
Expand All @@ -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{
Expand Down
1 change: 1 addition & 0 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func AddCommands(
tendermintCmd.AddCommand(
ShowNodeIDCmd(ctx),
ShowValidatorCmd(ctx),
ShowAddressCmd(ctx),
)

rootCmd.AddCommand(
Expand Down

0 comments on commit dc0f132

Please sign in to comment.