github.com/badrootd/nibiru-cometbft@v0.37.5-0.20240307173500-2a75559eee9b/cmd/cometbft/commands/gen_node_key.go (about) 1 package commands 2 3 import ( 4 "fmt" 5 6 "github.com/spf13/cobra" 7 8 cmtos "github.com/badrootd/nibiru-cometbft/libs/os" 9 "github.com/badrootd/nibiru-cometbft/p2p" 10 ) 11 12 // GenNodeKeyCmd allows the generation of a node key. It prints node's ID to 13 // the standard output. 14 var GenNodeKeyCmd = &cobra.Command{ 15 Use: "gen-node-key", 16 Aliases: []string{"gen_node_key"}, 17 Short: "Generate a node key for this node and print its ID", 18 RunE: genNodeKey, 19 } 20 21 func genNodeKey(cmd *cobra.Command, args []string) error { 22 nodeKeyFile := config.NodeKeyFile() 23 if cmtos.FileExists(nodeKeyFile) { 24 return fmt.Errorf("node key at %s already exists", nodeKeyFile) 25 } 26 27 nodeKey, err := p2p.LoadOrGenNodeKey(nodeKeyFile) 28 if err != nil { 29 return err 30 } 31 fmt.Println(nodeKey.ID()) 32 return nil 33 }