github.com/devwanda/aphelion-staking@v0.33.9/cmd/tendermint/commands/gen_node_key.go (about) 1 package commands 2 3 import ( 4 "fmt" 5 6 "github.com/spf13/cobra" 7 8 tmos "github.com/devwanda/aphelion-staking/libs/os" 9 "github.com/devwanda/aphelion-staking/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 Short: "Generate a node key for this node and print its ID", 17 RunE: genNodeKey, 18 } 19 20 func genNodeKey(cmd *cobra.Command, args []string) error { 21 nodeKeyFile := config.NodeKeyFile() 22 if tmos.FileExists(nodeKeyFile) { 23 return fmt.Errorf("node key at %s already exists", nodeKeyFile) 24 } 25 26 nodeKey, err := p2p.LoadOrGenNodeKey(nodeKeyFile) 27 if err != nil { 28 return err 29 } 30 fmt.Println(nodeKey.ID()) 31 return nil 32 }