-
Notifications
You must be signed in to change notification settings - Fork 40
/
consensus_key.go
36 lines (29 loc) · 976 Bytes
/
consensus_key.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package utils
import (
"fmt"
"github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/privval"
)
const (
outputPathFlag = "output-path"
)
func genConsensusKeyCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "gen-consensus-key",
Short: "generate the JSON file containing the private key to use as a validator in the consensus protocol",
RunE: runGenConsensusKeyCmd,
}
cmd.Flags().String(outputPathFlag, "./priv_validator_key.json", "The target path of the output file")
return cmd
}
func runGenConsensusKeyCmd(cmd *cobra.Command, args []string) error {
flags := cmd.Flags()
outputPath, _ := flags.GetString(outputPathFlag)
filePv := privval.GenFilePV(outputPath, "")
filePv.Key.Save()
fmt.Printf("The consensus key has been generated and saved to %s successfully\n", outputPath)
pubkey := types.MustBech32ifyConsPub(filePv.Key.PubKey)
fmt.Printf("The consensus pubkey is %s\n", pubkey)
return nil
}