github.com/vipernet-xyz/tm@v0.34.24/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/vipernet-xyz/tm/libs/os"
     9  	"github.com/vipernet-xyz/tm/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  	PreRun:  deprecateSnakeCase,
    19  	RunE:    genNodeKey,
    20  }
    21  
    22  func genNodeKey(cmd *cobra.Command, args []string) error {
    23  	nodeKeyFile := config.NodeKeyFile()
    24  	if tmos.FileExists(nodeKeyFile) {
    25  		return fmt.Errorf("node key at %s already exists", nodeKeyFile)
    26  	}
    27  
    28  	nodeKey, err := p2p.LoadOrGenNodeKey(nodeKeyFile)
    29  	if err != nil {
    30  		return err
    31  	}
    32  	fmt.Println(nodeKey.ID())
    33  	return nil
    34  }