Some checks are pending
docker-build-cometbft / vars (push) Waiting to run
docker-build-cometbft / build-images (amd64, ubuntu-24.04) (push) Blocked by required conditions
docker-build-cometbft / build-images (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
docker-build-cometbft / merge-images (push) Blocked by required conditions
docker-build-e2e-node / vars (push) Waiting to run
docker-build-e2e-node / build-images (amd64, ubuntu-24.04) (push) Blocked by required conditions
docker-build-e2e-node / build-images (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
docker-build-e2e-node / merge-images (push) Blocked by required conditions
41 lines
1,011 B
Go
41 lines
1,011 B
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
cmtjson "github.com/cometbft/cometbft/libs/json"
|
|
cmtos "github.com/cometbft/cometbft/libs/os"
|
|
"github.com/cometbft/cometbft/privval"
|
|
)
|
|
|
|
// ShowValidatorCmd adds capabilities for showing the validator info.
|
|
var ShowValidatorCmd = &cobra.Command{
|
|
Use: "show-validator",
|
|
Aliases: []string{"show_validator"},
|
|
Short: "Show this node's validator info",
|
|
RunE: showValidator,
|
|
}
|
|
|
|
func showValidator(*cobra.Command, []string) error {
|
|
keyFilePath := config.PrivValidatorKeyFile()
|
|
if !cmtos.FileExists(keyFilePath) {
|
|
return fmt.Errorf("private validator file %s does not exist", keyFilePath)
|
|
}
|
|
|
|
pv := privval.LoadFilePV(keyFilePath, config.PrivValidatorStateFile())
|
|
|
|
pubKey, err := pv.GetPubKey()
|
|
if err != nil {
|
|
return fmt.Errorf("can't get pubkey: %w", err)
|
|
}
|
|
|
|
bz, err := cmtjson.Marshal(pubKey)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to marshal private validator pubkey: %w", err)
|
|
}
|
|
|
|
fmt.Println(string(bz))
|
|
return nil
|
|
}
|