2018-04-05 03:31:33 -07:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2018-04-21 22:32:47 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/wire"
|
2018-04-05 03:31:33 -07:00
|
|
|
"github.com/spf13/cobra"
|
2018-04-19 12:18:31 -07:00
|
|
|
"github.com/spf13/viper"
|
2018-04-05 03:31:33 -07:00
|
|
|
|
2018-05-26 14:21:29 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2018-04-05 03:31:33 -07:00
|
|
|
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
|
|
|
"github.com/tendermint/tendermint/p2p"
|
2018-06-05 18:04:16 -07:00
|
|
|
pvm "github.com/tendermint/tendermint/privval"
|
2018-04-05 03:31:33 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// ShowNodeIDCmd - ported from Tendermint, dump node ID to stdout
|
|
|
|
func ShowNodeIDCmd(ctx *Context) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "show_node_id",
|
|
|
|
Short: "Show this node's ID",
|
2018-04-19 12:18:31 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
cfg := ctx.Config
|
|
|
|
nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println(nodeKey.ID())
|
|
|
|
return nil
|
|
|
|
},
|
2018-04-05 03:31:33 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ShowValidator - ported from Tendermint, show this node's validator info
|
|
|
|
func ShowValidatorCmd(ctx *Context) *cobra.Command {
|
2018-04-19 12:18:31 -07:00
|
|
|
flagJSON := "json"
|
|
|
|
cmd := cobra.Command{
|
2018-04-05 03:31:33 -07:00
|
|
|
Use: "show_validator",
|
2018-04-25 21:27:40 -07:00
|
|
|
Short: "Show this node's tendermint validator info",
|
2018-04-19 12:18:31 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-04-05 03:31:33 -07:00
|
|
|
|
2018-04-19 12:18:31 -07:00
|
|
|
cfg := ctx.Config
|
|
|
|
privValidator := pvm.LoadOrGenFilePV(cfg.PrivValidatorFile())
|
2018-05-27 05:21:15 -07:00
|
|
|
valPubKey := privValidator.PubKey
|
2018-04-05 03:31:33 -07:00
|
|
|
|
2018-04-19 12:18:31 -07:00
|
|
|
if viper.GetBool(flagJSON) {
|
2018-04-21 22:32:47 -07:00
|
|
|
|
|
|
|
cdc := wire.NewCodec()
|
|
|
|
wire.RegisterCrypto(cdc)
|
2018-05-27 05:21:15 -07:00
|
|
|
pubKeyJSONBytes, err := cdc.MarshalJSON(valPubKey)
|
2018-04-19 12:18:31 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println(string(pubKeyJSONBytes))
|
|
|
|
return nil
|
|
|
|
}
|
2018-06-01 07:23:58 -07:00
|
|
|
pubkey, err := sdk.Bech32ifyValPub(valPubKey)
|
2018-05-26 14:21:29 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-06-01 07:23:58 -07:00
|
|
|
fmt.Println(pubkey)
|
2018-04-19 12:18:31 -07:00
|
|
|
return nil
|
|
|
|
},
|
2018-04-05 03:31:33 -07:00
|
|
|
}
|
2018-04-19 12:18:31 -07:00
|
|
|
cmd.Flags().Bool(flagJSON, false, "get machine parseable output")
|
|
|
|
return &cmd
|
2018-04-05 03:31:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnsafeResetAllCmd - extension of the tendermint command, resets initialization
|
|
|
|
func UnsafeResetAllCmd(ctx *Context) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "unsafe_reset_all",
|
2018-04-25 21:27:40 -07:00
|
|
|
Short: "Reset blockchain database, priv_validator.json file, and the logger",
|
2018-04-19 12:18:31 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
cfg := ctx.Config
|
2018-06-29 14:52:00 -07:00
|
|
|
tcmd.ResetAll(cfg.DBDir(), cfg.P2P.AddrBookFile(), cfg.PrivValidatorFile(), ctx.Logger)
|
2018-04-19 12:18:31 -07:00
|
|
|
return nil
|
|
|
|
},
|
2018-04-05 03:31:33 -07:00
|
|
|
}
|
|
|
|
}
|