Merge pull request #705 from cosmos/cwgoes/show_node_id
Add show_node_id command (closes #704)
This commit is contained in:
commit
fb1a9495c3
|
@ -67,6 +67,7 @@ func main() {
|
|||
server.InitCmd(defaultOptions, logger),
|
||||
server.StartCmd(generateApp, logger),
|
||||
server.UnsafeResetAllCmd(logger),
|
||||
server.ShowNodeIdCmd(logger),
|
||||
version.VersionCmd,
|
||||
)
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue