diff --git a/examples/basecoin/cmd/basecoind/main.go b/examples/basecoin/cmd/basecoind/main.go index 56dfcc02f2b9..ea49c0b970e5 100644 --- a/examples/basecoin/cmd/basecoind/main.go +++ b/examples/basecoin/cmd/basecoind/main.go @@ -67,6 +67,7 @@ func main() { server.InitCmd(defaultOptions, logger), server.StartCmd(generateApp, logger), server.UnsafeResetAllCmd(logger), + server.ShowNodeIdCmd(logger), version.VersionCmd, ) diff --git a/server/show_node_id.go b/server/show_node_id.go new file mode 100644 index 000000000000..f8d9f3f81f6b --- /dev/null +++ b/server/show_node_id.go @@ -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 +}