Merge pull request #705 from cosmos/cwgoes/show_node_id

Add show_node_id command (closes #704)
This commit is contained in:
Rigel 2018-03-26 20:31:33 +02:00 committed by GitHub
commit fb1a9495c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View File

@ -67,6 +67,7 @@ func main() {
server.InitCmd(defaultOptions, logger),
server.StartCmd(generateApp, logger),
server.UnsafeResetAllCmd(logger),
server.ShowNodeIdCmd(logger),
version.VersionCmd,
)

38
server/show_node_id.go Normal file
View File

@ -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
}