forked from cosmos/cosmos-sdk
/
tx.go
63 lines (51 loc) · 1.65 KB
/
tx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package cli
import (
"errors"
"github.com/spf13/cobra"
"github.com/JaTochNietDan/cosmos-sdk/client"
"github.com/JaTochNietDan/cosmos-sdk/client/flags"
"github.com/JaTochNietDan/cosmos-sdk/client/tx"
"github.com/JaTochNietDan/cosmos-sdk/x/crisis/types"
)
// NewTxCmd returns a root CLI command handler for all x/crisis transaction commands.
func NewTxCmd() *cobra.Command {
txCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Crisis transactions subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
txCmd.AddCommand(NewMsgVerifyInvariantTxCmd())
return txCmd
}
// NewMsgVerifyInvariantTxCmd returns a CLI command handler for creating a
// MsgVerifyInvariant transaction.
func NewMsgVerifyInvariantTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "invariant-broken [module-name] [invariant-route]",
Short: "Submit proof that an invariant broken to halt the chain",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
moduleName, route := args[0], args[1]
if moduleName == "" {
return errors.New("invalid module name")
}
if route == "" {
return errors.New("invalid invariant route")
}
senderAddr := clientCtx.GetFromAddress()
msg := types.NewMsgVerifyInvariant(senderAddr, moduleName, route)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}