github.com/devwanda/aphelion-staking@v0.33.9/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/devwanda/aphelion-staking/libs/os"
    10  	"github.com/devwanda/aphelion-staking/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 errors.Wrap(err, "can't get pubkey")
    31  	}
    32  
    33  	bz, err := cdc.MarshalJSON(pubKey)
    34  	if err != nil {
    35  		return errors.Wrap(err, "failed to marshal private validator pubkey")
    36  	}
    37  
    38  	fmt.Println(string(bz))
    39  	return nil
    40  }