-
Notifications
You must be signed in to change notification settings - Fork 3
/
tx.go
115 lines (91 loc) · 2.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package cli
// DONTCOVER
// client is excluded from test coverage in MVP version
import (
"fmt"
"strings"
"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/cosmosquad-labs/squad/v2/x/liquidstaking/types"
)
// GetTxCmd returns a root CLI command handler for all x/liquidstaking transaction commands.
func GetTxCmd() *cobra.Command {
liquidstakingTxCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Liquid-staking transaction subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
liquidstakingTxCmd.AddCommand(
NewLiquidStakeCmd(),
NewLiquidUnstakeCmd(),
)
return liquidstakingTxCmd
}
// NewLiquidStakeCmd implements the liquid stake coin command handler.
func NewLiquidStakeCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "liquid-stake [amount]",
Args: cobra.ExactArgs(1),
Short: "Liquid-stake coin",
Long: strings.TrimSpace(
fmt.Sprintf(`Liquid-stake coin.
Example:
$ %s tx %s liquid-stake 1000stake --from mykey
`,
version.AppName, types.ModuleName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
liquidStaker := clientCtx.GetFromAddress()
stakingCoin, err := sdk.ParseCoinNormalized(args[0])
if err != nil {
return err
}
msg := types.NewMsgLiquidStake(liquidStaker, stakingCoin)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// NewLiquidUnstakeCmd implements the liquid unstake coin command handler.
func NewLiquidUnstakeCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "liquid-unstake [amount]",
Args: cobra.ExactArgs(1),
Short: "Liquid-unstake coin",
Long: strings.TrimSpace(
fmt.Sprintf(`Liquid-unstake coin.
Example:
$ %s tx %s liquid-unstake 500stake --from mykey
`,
version.AppName, types.ModuleName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
liquidStaker := clientCtx.GetFromAddress()
unstakingCoin, err := sdk.ParseCoinNormalized(args[0])
if err != nil {
return err
}
msg := types.NewMsgLiquidUnstake(liquidStaker, unstakingCoin)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}