2018-04-05 03:31:33 -07:00
|
|
|
package server
|
|
|
|
|
2019-02-08 13:45:41 -08:00
|
|
|
// DONTCOVER
|
|
|
|
|
2018-04-05 03:31:33 -07:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2018-04-19 12:18:31 -07:00
|
|
|
"github.com/spf13/viper"
|
2019-05-31 06:14:35 -07:00
|
|
|
"gopkg.in/yaml.v2"
|
2018-04-05 03:31:33 -07:00
|
|
|
|
|
|
|
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
2019-01-24 02:15:44 -08:00
|
|
|
"github.com/tendermint/tendermint/libs/cli"
|
2018-04-05 03:31:33 -07:00
|
|
|
"github.com/tendermint/tendermint/p2p"
|
2018-06-05 18:04:16 -07:00
|
|
|
pvm "github.com/tendermint/tendermint/privval"
|
2019-01-11 20:30:16 -08:00
|
|
|
tversion "github.com/tendermint/tendermint/version"
|
2018-12-10 06:27:25 -08:00
|
|
|
|
2019-01-24 02:15:44 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2018-12-10 06:27:25 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
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{
|
2018-08-14 01:23:42 -07:00
|
|
|
Use: "show-node-id",
|
2018-04-05 03:31:33 -07:00
|
|
|
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
|
|
|
cmd := cobra.Command{
|
2018-08-14 01:23:42 -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
|
2019-01-11 09:19:01 -08:00
|
|
|
UpgradeOldPrivValFile(cfg)
|
|
|
|
privValidator := pvm.LoadOrGenFilePV(
|
|
|
|
cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile())
|
|
|
|
valPubKey := privValidator.GetPubKey()
|
2018-04-05 03:31:33 -07:00
|
|
|
|
2019-01-24 02:15:44 -08:00
|
|
|
if viper.GetString(cli.OutputFlag) == "json" {
|
2018-08-30 18:38:28 -07:00
|
|
|
return printlnJSON(valPubKey)
|
2018-04-19 12:18:31 -07:00
|
|
|
}
|
2018-08-30 21:06:44 -07:00
|
|
|
|
|
|
|
pubkey, err := sdk.Bech32ifyConsPub(valPubKey)
|
2018-05-26 14:21:29 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-30 21:06:44 -07:00
|
|
|
|
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
|
|
|
}
|
2019-01-24 02:15:44 -08:00
|
|
|
|
|
|
|
cmd.Flags().StringP(cli.OutputFlag, "o", "text", "Output format (text|json)")
|
2018-04-19 12:18:31 -07:00
|
|
|
return &cmd
|
2018-04-05 03:31:33 -07:00
|
|
|
}
|
|
|
|
|
2018-08-30 18:38:28 -07:00
|
|
|
// ShowAddressCmd - show this node's validator address
|
|
|
|
func ShowAddressCmd(ctx *Context) *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "show-address",
|
2018-11-11 23:34:50 -08:00
|
|
|
Short: "Shows this node's tendermint validator consensus address",
|
2018-08-30 18:38:28 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2019-01-11 09:19:01 -08:00
|
|
|
|
2018-08-30 18:38:28 -07:00
|
|
|
cfg := ctx.Config
|
2019-01-11 09:19:01 -08:00
|
|
|
UpgradeOldPrivValFile(cfg)
|
|
|
|
privValidator := pvm.LoadOrGenFilePV(
|
|
|
|
cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile())
|
|
|
|
valConsAddr := (sdk.ConsAddress)(privValidator.GetAddress())
|
2018-08-30 18:38:28 -07:00
|
|
|
|
2019-01-24 02:15:44 -08:00
|
|
|
if viper.GetString(cli.OutputFlag) == "json" {
|
2018-11-11 23:34:50 -08:00
|
|
|
return printlnJSON(valConsAddr)
|
2018-08-30 18:38:28 -07:00
|
|
|
}
|
|
|
|
|
2018-11-11 23:34:50 -08:00
|
|
|
fmt.Println(valConsAddr.String())
|
2018-08-30 18:38:28 -07:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-01-24 02:15:44 -08:00
|
|
|
cmd.Flags().StringP(cli.OutputFlag, "o", "text", "Output format (text|json)")
|
2018-08-30 18:38:28 -07:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2019-01-11 20:30:16 -08:00
|
|
|
// VersionCmd prints tendermint and ABCI version numbers.
|
|
|
|
func VersionCmd(ctx *Context) *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "version",
|
|
|
|
Short: "Print tendermint libraries' version",
|
2019-01-14 05:38:52 -08:00
|
|
|
Long: `Print protocols' and libraries' version numbers
|
2019-01-11 20:30:16 -08:00
|
|
|
against which this app has been compiled.
|
|
|
|
`,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
|
2019-05-31 06:14:35 -07:00
|
|
|
bs, err := yaml.Marshal(&struct {
|
|
|
|
Tendermint string
|
|
|
|
ABCI string
|
|
|
|
BlockProtocol uint64
|
|
|
|
P2PProtocol uint64
|
|
|
|
}{
|
|
|
|
Tendermint: tversion.Version,
|
|
|
|
ABCI: tversion.ABCIVersion,
|
|
|
|
BlockProtocol: tversion.BlockProtocol.Uint64(),
|
|
|
|
P2PProtocol: tversion.P2PProtocol.Uint64(),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-01-11 20:30:16 -08:00
|
|
|
|
2019-05-31 06:14:35 -07:00
|
|
|
fmt.Println(string(bs))
|
2019-01-11 20:30:16 -08:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2018-08-30 18:38:28 -07:00
|
|
|
func printlnJSON(v interface{}) error {
|
2018-09-13 11:17:32 -07:00
|
|
|
cdc := codec.New()
|
|
|
|
codec.RegisterCrypto(cdc)
|
2018-08-30 18:38:28 -07:00
|
|
|
marshalled, err := cdc.MarshalJSON(v)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println(string(marshalled))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
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{
|
2018-08-14 01:23:42 -07:00
|
|
|
Use: "unsafe-reset-all",
|
2018-08-10 23:42:57 -07:00
|
|
|
Short: "Resets the blockchain database, removes address book files, and resets priv_validator.json to the genesis state",
|
2018-04-19 12:18:31 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
cfg := ctx.Config
|
2019-01-11 09:19:01 -08:00
|
|
|
tcmd.ResetAll(cfg.DBDir(), cfg.P2P.AddrBookFile(), cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile(), ctx.Logger)
|
2018-04-19 12:18:31 -07:00
|
|
|
return nil
|
|
|
|
},
|
2018-04-05 03:31:33 -07:00
|
|
|
}
|
|
|
|
}
|