2019-03-28 16:27:47 -07:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2020-07-08 01:23:34 -07:00
|
|
|
"errors"
|
|
|
|
|
2019-03-28 16:27:47 -07:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2019-12-23 08:05:47 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
2020-04-02 12:07:47 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/tx"
|
2020-03-03 08:45:02 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/crisis/types"
|
2019-03-28 16:27:47 -07:00
|
|
|
)
|
|
|
|
|
2020-04-02 12:07:47 -07:00
|
|
|
// NewTxCmd returns a root CLI command handler for all x/crisis transaction commands.
|
2020-07-08 01:23:34 -07:00
|
|
|
func NewTxCmd() *cobra.Command {
|
2020-04-02 12:07:47 -07:00
|
|
|
txCmd := &cobra.Command{
|
|
|
|
Use: types.ModuleName,
|
|
|
|
Short: "Crisis transactions subcommands",
|
|
|
|
DisableFlagParsing: true,
|
|
|
|
SuggestionsMinimumDistance: 2,
|
|
|
|
RunE: client.ValidateCmd,
|
|
|
|
}
|
|
|
|
|
2020-07-08 01:23:34 -07:00
|
|
|
txCmd.AddCommand(NewMsgVerifyInvariantTxCmd())
|
2020-04-02 12:07:47 -07:00
|
|
|
|
|
|
|
return txCmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewMsgVerifyInvariantTxCmd returns a CLI command handler for creating a
|
|
|
|
// MsgVerifyInvariant transaction.
|
2020-07-08 01:23:34 -07:00
|
|
|
func NewMsgVerifyInvariantTxCmd() *cobra.Command {
|
2019-03-28 16:27:47 -07:00
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "invariant-broken [module-name] [invariant-route]",
|
2020-04-02 12:07:47 -07:00
|
|
|
Short: "Submit proof that an invariant broken to halt the chain",
|
2019-03-28 16:27:47 -07:00
|
|
|
Args: cobra.ExactArgs(2),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2020-07-08 01:23:34 -07:00
|
|
|
clientCtx := client.GetClientContextFromCmd(cmd)
|
|
|
|
|
|
|
|
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-03-28 16:27:47 -07:00
|
|
|
|
|
|
|
moduleName, route := args[0], args[1]
|
2020-07-08 01:23:34 -07:00
|
|
|
if moduleName == "" {
|
|
|
|
return errors.New("invalid module name")
|
|
|
|
}
|
|
|
|
if route == "" {
|
|
|
|
return errors.New("invalid invariant route")
|
|
|
|
}
|
|
|
|
|
|
|
|
senderAddr := clientCtx.GetFromAddress()
|
2020-04-02 12:07:47 -07:00
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
msg := types.NewMsgVerifyInvariant(senderAddr, moduleName, route)
|
2020-04-09 07:00:10 -07:00
|
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-08 01:23:34 -07:00
|
|
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
2019-03-28 16:27:47 -07:00
|
|
|
},
|
|
|
|
}
|
2020-04-02 12:07:47 -07:00
|
|
|
|
2020-07-11 01:13:46 -07:00
|
|
|
flags.AddTxFlagsToCmd(cmd)
|
|
|
|
|
|
|
|
return cmd
|
2019-03-28 16:27:47 -07:00
|
|
|
}
|