Add show_validator command (ref #704)

This commit is contained in:
Christopher Goes 2018-03-27 11:47:41 +02:00
parent d0eb05b162
commit 4371667673
2 changed files with 38 additions and 0 deletions

View File

@ -69,6 +69,7 @@ func main() {
server.StartCmd(generateApp, logger),
server.UnsafeResetAllCmd(logger),
server.ShowNodeIdCmd(logger),
server.ShowValidatorCmd(logger),
version.VersionCmd,
)

37
server/show_validator.go Normal file
View File

@ -0,0 +1,37 @@
package server
import (
"fmt"
"github.com/spf13/cobra"
"github.com/tendermint/go-wire/data"
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tmlibs/log"
)
// ShowValidator - ported from Tendermint, show this node's validator info
func ShowValidatorCmd(logger log.Logger) *cobra.Command {
cmd := showValidator{logger}
return &cobra.Command{
Use: "show_validator",
Short: "Show this node's validator info",
RunE: cmd.run,
}
}
type showValidator struct {
logger log.Logger
}
func (s showValidator) run(cmd *cobra.Command, args []string) error {
cfg, err := tcmd.ParseConfig()
if err != nil {
return err
}
privValidator := types.LoadOrGenPrivValidatorFS(cfg.PrivValidatorFile())
pubKeyJSONBytes, _ := data.ToJSON(privValidator.PubKey)
fmt.Println(string(pubKeyJSONBytes))
return nil
}