From d808ecb662fd70eb60e301f50644b0f479c8d98f Mon Sep 17 00:00:00 2001 From: Omri Date: Tue, 10 Jan 2023 15:42:50 +0100 Subject: [PATCH] Added show-sequencer command to print the sequencer pubkey. (#178) --- cmd/dymint/commands/show_sequencer.go | 41 +++++++++++++++++++++++++++ cmd/dymint/main.go | 1 + 2 files changed, 42 insertions(+) create mode 100644 cmd/dymint/commands/show_sequencer.go diff --git a/cmd/dymint/commands/show_sequencer.go b/cmd/dymint/commands/show_sequencer.go new file mode 100644 index 000000000..5f98dc2ba --- /dev/null +++ b/cmd/dymint/commands/show_sequencer.go @@ -0,0 +1,41 @@ +package commands + +import ( + "fmt" + + "github.com/spf13/cobra" + tmjson "github.com/tendermint/tendermint/libs/json" + tmos "github.com/tendermint/tendermint/libs/os" + "github.com/tendermint/tendermint/privval" +) + +// ShowSequencer adds capabilities for showing the validator info. +var ShowSequencer = &cobra.Command{ + Use: "show-sequencer", + Aliases: []string{"show_sequencer"}, + Short: "Show this node's sequencer info", + RunE: showSequencer, + // PreRun: deprecateSnakeCase, +} + +func showSequencer(cmd *cobra.Command, args []string) error { + keyFilePath := tmconfig.PrivValidatorKeyFile() + if !tmos.FileExists(keyFilePath) { + return fmt.Errorf("sequencer file %s does not exist", keyFilePath) + } + + pv := privval.LoadFilePV(keyFilePath, tmconfig.PrivValidatorStateFile()) + + pubKey, err := pv.GetPubKey() + if err != nil { + return fmt.Errorf("can't get pubkey: %w", err) + } + + bz, err := tmjson.Marshal(pubKey) + if err != nil { + return fmt.Errorf("failed to marshal sequencer pubkey: %w", err) + } + + fmt.Println(string(bz)) + return nil +} diff --git a/cmd/dymint/main.go b/cmd/dymint/main.go index 97b58e053..f972b3678 100644 --- a/cmd/dymint/main.go +++ b/cmd/dymint/main.go @@ -14,6 +14,7 @@ func main() { rootCmd := commands.RootCmd rootCmd.AddCommand( commands.InitFilesCmd, + commands.ShowSequencer, debug.DebugCmd, cli.NewCompletionCmd(rootCmd, true), )