Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add show-address command #2170

Merged
merged 4 commits into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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