github.com/number571/tendermint@v0.34.11-gost/cmd/tendermint/commands/gen_node_key.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/spf13/cobra"
     7  
     8  	tmjson "github.com/number571/tendermint/libs/json"
     9  	"github.com/number571/tendermint/types"
    10  )
    11  
    12  // GenNodeKeyCmd allows the generation of a node key. It prints JSON-encoded
    13  // NodeKey to the standard output.
    14  var GenNodeKeyCmd = &cobra.Command{
    15  	Use:     "gen-node-key",
    16  	Aliases: []string{"gen_node_key"},
    17  	Short:   "Generate a new node key",
    18  	RunE:    genNodeKey,
    19  	PreRun:  deprecateSnakeCase,
    20  }
    21  
    22  func genNodeKey(cmd *cobra.Command, args []string) error {
    23  	nodeKey := types.GenNodeKey()
    24  
    25  	bz, err := tmjson.Marshal(nodeKey)
    26  	if err != nil {
    27  		return fmt.Errorf("nodeKey -> json: %w", err)
    28  	}
    29  
    30  	fmt.Printf(`%v
    31  `, string(bz))
    32  
    33  	return nil
    34  }