Skip to content

Commit

Permalink
Added command to show the p2p node id. (dymensionxyz#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
omritoptix authored Jan 15, 2023
1 parent 2174584 commit d2e6d13
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cmd/dymint/commands/show_node_id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package commands

import (
"fmt"

"github.com/dymensionxyz/dymint/conv"
"github.com/libp2p/go-libp2p"
"github.com/spf13/cobra"

"github.com/tendermint/tendermint/p2p"
)

// ShowNodeIDCmd dumps node's ID to the standard output.
var ShowNodeIDCmd = &cobra.Command{
Use: "show-node-id",
Aliases: []string{"show_node_id"},
Short: "Show this node's ID",
RunE: showNodeID,
}

func showNodeID(cmd *cobra.Command, args []string) error {
nodeKey, err := p2p.LoadNodeKey(tmconfig.NodeKeyFile())
if err != nil {
return err
}
signingKey, err := conv.GetNodeKey(nodeKey)
if err != nil {
return err
}
// convert nodeKey to libp2p key
host, err := libp2p.New(libp2p.Identity(signingKey))
if err != nil {
return err
}

fmt.Println(host.ID())
return nil
}
1 change: 1 addition & 0 deletions cmd/dymint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func main() {
rootCmd.AddCommand(
commands.InitFilesCmd,
commands.ShowSequencer,
commands.ShowNodeIDCmd,
debug.DebugCmd,
cli.NewCompletionCmd(rootCmd, true),
)
Expand Down

0 comments on commit d2e6d13

Please sign in to comment.