github.com/badrootd/nibiru-cometbft@v0.37.5-0.20240307173500-2a75559eee9b/cmd/cometbft/commands/show_validator.go (about) 1 package commands 2 3 import ( 4 "fmt" 5 6 "github.com/spf13/cobra" 7 8 cmtjson "github.com/badrootd/nibiru-cometbft/libs/json" 9 cmtos "github.com/badrootd/nibiru-cometbft/libs/os" 10 "github.com/badrootd/nibiru-cometbft/privval" 11 ) 12 13 // ShowValidatorCmd adds capabilities for showing the validator info. 14 var ShowValidatorCmd = &cobra.Command{ 15 Use: "show-validator", 16 Aliases: []string{"show_validator"}, 17 Short: "Show this node's validator info", 18 RunE: showValidator, 19 } 20 21 func showValidator(cmd *cobra.Command, args []string) error { 22 keyFilePath := config.PrivValidatorKeyFile() 23 if !cmtos.FileExists(keyFilePath) { 24 return fmt.Errorf("private validator file %s does not exist", keyFilePath) 25 } 26 27 pv := privval.LoadFilePV(keyFilePath, config.PrivValidatorStateFile()) 28 29 pubKey, err := pv.GetPubKey() 30 if err != nil { 31 return fmt.Errorf("can't get pubkey: %w", err) 32 } 33 34 bz, err := cmtjson.Marshal(pubKey) 35 if err != nil { 36 return fmt.Errorf("failed to marshal private validator pubkey: %w", err) 37 } 38 39 fmt.Println(string(bz)) 40 return nil 41 }