Skip to content

Commit

Permalink
Add show_node_id command (closes #704)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes committed Mar 26, 2018
1 parent 2d45058 commit 3126afd
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 3126afd

Please sign in to comment.