github.com/pokt-network/tendermint@v0.32.11-0.20230426215212-59310158d3e9/cmd/tendermint/commands/show_validator.go (about) 1 package commands 2 3 import ( 4 "fmt" 5 6 "github.com/pkg/errors" 7 "github.com/spf13/cobra" 8 9 tmos "github.com/tendermint/tendermint/libs/os" 10 "github.com/tendermint/tendermint/privval" 11 ) 12 13 // ShowValidatorCmd adds capabilities for showing the validator info. 14 var ShowValidatorCmd = &cobra.Command{ 15 Use: "show_validator", 16 Short: "Show this node's validator info", 17 RunE: showValidator, 18 } 19 20 func showValidator(cmd *cobra.Command, args []string) error { 21 keyFilePath := config.PrivValidatorKeyFile() 22 if !tmos.FileExists(keyFilePath) { 23 return fmt.Errorf("private validator file %s does not exist", keyFilePath) 24 } 25 26 pv := privval.LoadFilePVLean(keyFilePath, config.PrivValidatorStateFile()) 27 28 pubKeys, err := pv.GetPubKeys() 29 if err != nil { 30 return errors.Wrap(err, "can't get pubkey") 31 } 32 if len(pubKeys) > 1 { 33 return errors.Wrapf(err, "expected exactly one public key but got %d", len(pubKeys)) 34 } 35 pubKey := pubKeys[0] 36 37 bz, err := cdc.MarshalJSON(pubKey) 38 if err != nil { 39 return errors.Wrap(err, "failed to marshal private validator pubkey") 40 } 41 42 fmt.Println(string(bz)) 43 return nil 44 }