From 384b3ea0652e30cc0b650d754611eae66243d80a Mon Sep 17 00:00:00 2001 From: suyuhuang Date: Tue, 10 Apr 2018 22:03:51 +0800 Subject: [PATCH] improve `show_node_id` (#1433) * fix show_node_id * make LoadNodeKey public * make LoadNodeKey public * remove if * remove if --- cmd/tendermint/commands/show_node_id.go | 5 ++++- p2p/key.go | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/tendermint/commands/show_node_id.go b/cmd/tendermint/commands/show_node_id.go index 92af49417..1d94933ef 100644 --- a/cmd/tendermint/commands/show_node_id.go +++ b/cmd/tendermint/commands/show_node_id.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/cobra" "github.com/tendermint/tendermint/p2p" + ) // ShowNodeIDCmd dumps node's ID to the standard output. @@ -16,10 +17,12 @@ var ShowNodeIDCmd = &cobra.Command{ } func showNodeID(cmd *cobra.Command, args []string) error { - nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile()) + + nodeKey, err := p2p.LoadNodeKey(config.NodeKeyFile()) if err != nil { return err } fmt.Println(nodeKey.ID()) + return nil } diff --git a/p2p/key.go b/p2p/key.go index 9b8087cd4..73103ebd4 100644 --- a/p2p/key.go +++ b/p2p/key.go @@ -47,7 +47,7 @@ func PubKeyToID(pubKey crypto.PubKey) ID { // If the file does not exist, it generates and saves a new NodeKey. func LoadOrGenNodeKey(filePath string) (*NodeKey, error) { if cmn.FileExists(filePath) { - nodeKey, err := loadNodeKey(filePath) + nodeKey, err := LoadNodeKey(filePath) if err != nil { return nil, err } @@ -56,7 +56,7 @@ func LoadOrGenNodeKey(filePath string) (*NodeKey, error) { return genNodeKey(filePath) } -func loadNodeKey(filePath string) (*NodeKey, error) { +func LoadNodeKey(filePath string) (*NodeKey, error) { jsonBytes, err := ioutil.ReadFile(filePath) if err != nil { return nil, err