github.com/vipernet-xyz/tm@v0.34.24/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/vipernet-xyz/tm/libs/json"
     9  	tmos "github.com/vipernet-xyz/tm/libs/os"
    10  	"github.com/vipernet-xyz/tm/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  	PreRun:  deprecateSnakeCase,
    20  }
    21  
    22  func showValidator(cmd *cobra.Command, args []string) error {
    23  	keyFilePath := config.PrivValidatorKeyFile()
    24  	if !tmos.FileExists(keyFilePath) {
    25  		return fmt.Errorf("private validator file %s does not exist", keyFilePath)
    26  	}
    27  
    28  	pv := privval.LoadFilePV(keyFilePath, config.PrivValidatorStateFile())
    29  
    30  	pubKey, err := pv.GetPubKey()
    31  	if err != nil {
    32  		return fmt.Errorf("can't get pubkey: %w", err)
    33  	}
    34  
    35  	bz, err := tmjson.Marshal(pubKey)
    36  	if err != nil {
    37  		return fmt.Errorf("failed to marshal private validator pubkey: %w", err)
    38  	}
    39  
    40  	fmt.Println(string(bz))
    41  	return nil
    42  }