Merge pull request #710 from cosmos/cwgoes/show_validator

Add show_validator command from tendermint to basecoind
This commit is contained in:
Rigel
2018-03-28 18:57:05 +02:00
committed by GitHub
2 changed files with 41 additions and 0 deletions
+1
View File
@@ -69,6 +69,7 @@ func main() {
server.StartCmd(generateApp, logger),
server.UnsafeResetAllCmd(logger),
server.ShowNodeIdCmd(logger),
server.ShowValidatorCmd(logger),
version.VersionCmd,
)
+40
View File
@@ -0,0 +1,40 @@
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, err := data.ToJSON(privValidator.PubKey)
if err != nil {
return err
}
fmt.Println(string(pubKeyJSONBytes))
return nil
}