/
tx.go
91 lines (78 loc) · 2.23 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package cli
import (
"fmt"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/kava-labs/kava/x/savings/types"
)
// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
savingsTxCmd := &cobra.Command{
Use: types.ModuleName,
Short: "savings transactions subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmds := []*cobra.Command{
getCmdDeposit(),
getCmdWithdraw(),
}
for _, cmd := range cmds {
flags.AddTxFlagsToCmd(cmd)
}
savingsTxCmd.AddCommand(cmds...)
return savingsTxCmd
}
func getCmdDeposit() *cobra.Command {
return &cobra.Command{
Use: "deposit [amount]",
Short: "deposit coins to savings",
Example: fmt.Sprintf(
`%s tx %s deposit 10000000ukava,100000000usdx --from <key>`, version.AppName, types.ModuleName,
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
amount, err := sdk.ParseCoinsNormalized(args[0])
if err != nil {
return err
}
msg := types.NewMsgDeposit(clientCtx.GetFromAddress(), amount)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}
}
func getCmdWithdraw() *cobra.Command {
return &cobra.Command{
Use: "withdraw [amount]",
Short: "withdraw coins from savings",
Example: fmt.Sprintf(
`%s tx %s withdraw 10000000ukava,100000000usdx --from <key>`, version.AppName, types.ModuleName,
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
amount, err := sdk.ParseCoinsNormalized(args[0])
if err != nil {
return err
}
msg := types.NewMsgWithdraw(clientCtx.GetFromAddress(), amount)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}
}