Skip to content

Commit

Permalink
Merge pull request #705 from cosmos/cwgoes/show_node_id
Browse files Browse the repository at this point in the history
Add show_node_id command (closes #704)
  • Loading branch information
rigelrozanski authored Mar 26, 2018
2 parents 2d45058 + 3126afd commit fb1a949
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/basecoin/cmd/basecoind/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func main() {
server.InitCmd(defaultOptions, logger),
server.StartCmd(generateApp, logger),
server.UnsafeResetAllCmd(logger),
server.ShowNodeIdCmd(logger),
version.VersionCmd,
)

Expand Down
38 changes: 38 additions & 0 deletions server/show_node_id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package server

import (
"fmt"

"github.com/spf13/cobra"

tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tmlibs/log"
)

// ShowNodeIdCmd - ported from Tendermint, dump node ID to stdout
func ShowNodeIdCmd(logger log.Logger) *cobra.Command {
cmd := showNodeId{logger}
return &cobra.Command{
Use: "show_node_id",
Short: "Show this node's ID",
RunE: cmd.run,
}
}

type showNodeId struct {
logger log.Logger
}

func (s showNodeId) run(cmd *cobra.Command, args []string) error {
cfg, err := tcmd.ParseConfig()
if err != nil {
return err
}
nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile())
if err != nil {
return err
}
fmt.Println(nodeKey.ID())
return nil
}

0 comments on commit fb1a949

Please sign in to comment.