github.com/adoriasoft/tendermint@v0.34.0-dev1.0.20200722151356-96d84601a75a/cmd/tendermint/commands/show_validator.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/spf13/cobra"
     7  
     8  	tmjson "github.com/tendermint/tendermint/libs/json"
     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.LoadFilePV(keyFilePath, config.PrivValidatorStateFile())
    27  
    28  	pubKey, err := pv.GetPubKey()
    29  	if err != nil {
    30  		return fmt.Errorf("can't get pubkey: %w", err)
    31  	}
    32  
    33  	bz, err := tmjson.Marshal(pubKey)
    34  	if err != nil {
    35  		return fmt.Errorf("failed to marshal private validator pubkey: %w", err)
    36  	}
    37  
    38  	fmt.Println(string(bz))
    39  	return nil
    40  }