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"
|
|
|
|
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
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"
|
2021-09-24 07:37:34 -07:00
|
|
|
"sigs.k8s.io/yaml"
|
2018-12-10 06:27:25 -08:00
|
|
|
|
2021-03-25 07:53:22 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2020-06-04 03:38:24 -07:00
|
|
|
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/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
|
2020-07-07 08:40:46 -07:00
|
|
|
func ShowNodeIDCmd() *cobra.Command {
|
2018-04-05 03:31:33 -07:00
|
|
|
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 {
|
2020-07-07 08:40:46 -07:00
|
|
|
serverCtx := GetServerContextFromCmd(cmd)
|
|
|
|
cfg := serverCtx.Config
|
|
|
|
|
2021-11-16 11:24:38 -08:00
|
|
|
nodeKey, err := cfg.LoadNodeKeyID()
|
2018-04-19 12:18:31 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-11-16 11:24:38 -08:00
|
|
|
fmt.Println(nodeKey)
|
2018-04-19 12:18:31 -07:00
|
|
|
return nil
|
|
|
|
},
|
2018-04-05 03:31:33 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-09 08:01:43 -08:00
|
|
|
// ShowValidatorCmd - ported from Tendermint, show this node's validator info
|
2020-07-07 08:40:46 -07:00
|
|
|
func ShowValidatorCmd() *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 {
|
2020-07-07 08:40:46 -07:00
|
|
|
serverCtx := GetServerContextFromCmd(cmd)
|
|
|
|
cfg := serverCtx.Config
|
2020-04-22 12:21:48 -07:00
|
|
|
|
2021-11-16 11:24:38 -08:00
|
|
|
privValidator, err := pvm.LoadFilePV(cfg.PrivValidator.KeyFile(), cfg.PrivValidator.StateFile())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
pk, err := privValidator.GetPubKey(cmd.Context())
|
2020-04-22 12:21:48 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-03-25 07:53:22 -07:00
|
|
|
sdkPK, err := cryptocodec.FromTmPubKeyInterface(pk)
|
2020-11-09 08:01:43 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-03-25 07:53:22 -07:00
|
|
|
clientCtx := client.GetClientContextFromCmd(cmd)
|
2021-06-11 04:49:39 -07:00
|
|
|
bz, err := clientCtx.Codec.MarshalInterfaceJSON(sdkPK)
|
2018-05-26 14:21:29 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-03-25 07:53:22 -07:00
|
|
|
fmt.Println(string(bz))
|
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
|
|
|
|
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
|
2020-07-07 08:40:46 -07:00
|
|
|
func ShowAddressCmd() *cobra.Command {
|
2018-08-30 18:38:28 -07:00
|
|
|
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 {
|
2020-07-07 08:40:46 -07:00
|
|
|
serverCtx := GetServerContextFromCmd(cmd)
|
|
|
|
cfg := serverCtx.Config
|
|
|
|
|
2021-11-16 11:24:38 -08:00
|
|
|
privValidator, err := pvm.LoadFilePV(cfg.PrivValidator.Key, cfg.PrivValidator.State)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-01-11 09:19:01 -08:00
|
|
|
valConsAddr := (sdk.ConsAddress)(privValidator.GetAddress())
|
2018-11-11 23:34:50 -08:00
|
|
|
fmt.Println(valConsAddr.String())
|
2018-08-30 18:38:28 -07:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2019-01-11 20:30:16 -08:00
|
|
|
// VersionCmd prints tendermint and ABCI version numbers.
|
2020-07-07 08:40:46 -07:00
|
|
|
func VersionCmd() *cobra.Command {
|
|
|
|
return &cobra.Command{
|
2019-01-11 20:30:16 -08:00
|
|
|
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
|
|
|
|
}{
|
2021-11-16 11:24:38 -08:00
|
|
|
Tendermint: tversion.TMVersion,
|
2019-05-31 06:14:35 -07:00
|
|
|
ABCI: tversion.ABCIVersion,
|
2020-08-14 10:58:53 -07:00
|
|
|
BlockProtocol: tversion.BlockProtocol,
|
|
|
|
P2PProtocol: tversion.P2PProtocol,
|
2019-05-31 06:14:35 -07:00
|
|
|
})
|
|
|
|
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
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-05 03:31:33 -07:00
|
|
|
// UnsafeResetAllCmd - extension of the tendermint command, resets initialization
|
2020-07-07 08:40:46 -07:00
|
|
|
func UnsafeResetAllCmd() *cobra.Command {
|
2018-04-05 03:31:33 -07:00
|
|
|
return &cobra.Command{
|
2018-08-14 01:23:42 -07:00
|
|
|
Use: "unsafe-reset-all",
|
2020-10-10 04:02:12 -07:00
|
|
|
Short: "Resets the blockchain database, removes address book files, and resets data/priv_validator_state.json to the genesis state",
|
2018-04-19 12:18:31 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2020-07-07 08:40:46 -07:00
|
|
|
serverCtx := GetServerContextFromCmd(cmd)
|
|
|
|
cfg := serverCtx.Config
|
|
|
|
|
2021-11-16 11:24:38 -08:00
|
|
|
tcmd.ResetAll(cfg.DBDir(), cfg.P2P.AddrBookFile(), cfg.PrivValidator.Key, cfg.PrivValidator.State, serverCtx.Logger)
|
2018-04-19 12:18:31 -07:00
|
|
|
return nil
|
|
|
|
},
|
2018-04-05 03:31:33 -07:00
|
|
|
}
|
|
|
|
}
|