github.com/lazyledger/lazyledger-core@v0.35.0-dev.0.20210613111200-4c651f053571/cmd/tendermint/commands/gen_validator.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/spf13/cobra"
     7  
     8  	tmjson "github.com/lazyledger/lazyledger-core/libs/json"
     9  	"github.com/lazyledger/lazyledger-core/privval"
    10  	"github.com/lazyledger/lazyledger-core/types"
    11  )
    12  
    13  // GenValidatorCmd allows the generation of a keypair for a
    14  // validator.
    15  var GenValidatorCmd = &cobra.Command{
    16  	Use:     "gen-validator",
    17  	Aliases: []string{"gen_validator"},
    18  	Short:   "Generate new validator keypair",
    19  	RunE:    genValidator,
    20  	PreRun:  deprecateSnakeCase,
    21  }
    22  
    23  func init() {
    24  	GenValidatorCmd.Flags().StringVar(&keyType, "key", types.ABCIPubKeyTypeEd25519,
    25  		"Key type to generate privval file with. Options: ed25519, secp256k1")
    26  }
    27  
    28  func genValidator(cmd *cobra.Command, args []string) error {
    29  	pv, err := privval.GenFilePV("", "", keyType)
    30  	if err != nil {
    31  		return err
    32  	}
    33  
    34  	jsbz, err := tmjson.Marshal(pv)
    35  	if err != nil {
    36  		return fmt.Errorf("validator -> json: %w", err)
    37  	}
    38  
    39  	fmt.Printf(`%v
    40  `, string(jsbz))
    41  
    42  	return nil
    43  }