2022-03-22 21:13:27 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2022-03-23 14:34:23 +00:00
|
|
|
"fmt"
|
|
|
|
|
2022-03-22 21:13:27 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
2022-03-23 14:34:23 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/tx"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/version"
|
2022-03-22 21:13:27 +00:00
|
|
|
|
|
|
|
"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,
|
|
|
|
}
|
|
|
|
|
2022-03-23 14:34:23 +00:00
|
|
|
cmds := []*cobra.Command{
|
|
|
|
getCmdDeposit(),
|
2022-03-28 11:53:42 +00:00
|
|
|
getCmdWithdraw(),
|
2022-03-23 14:34:23 +00:00
|
|
|
}
|
2022-03-22 21:13:27 +00:00
|
|
|
|
|
|
|
for _, cmd := range cmds {
|
|
|
|
flags.AddTxFlagsToCmd(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
savingsTxCmd.AddCommand(cmds...)
|
|
|
|
|
|
|
|
return savingsTxCmd
|
|
|
|
}
|
2022-03-23 14:34:23 +00:00
|
|
|
|
|
|
|
func getCmdDeposit() *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "deposit [amount]",
|
|
|
|
Short: "deposit coins to savings",
|
|
|
|
Example: fmt.Sprintf(
|
2022-03-28 11:53:42 +00:00
|
|
|
`%s tx %s deposit 10000000ukava,100000000usdx --from <key>`, version.AppName, types.ModuleName,
|
2022-03-23 14:34:23 +00:00
|
|
|
),
|
|
|
|
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)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2022-03-28 11:53:42 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|