-
Notifications
You must be signed in to change notification settings - Fork 55
/
tx.go
87 lines (72 loc) 路 2.18 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
package cli
import (
"fmt"
"strconv"
"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"
"github.com/cosmos/cosmos-sdk/version"
"github.com/crescent-network/crescent/v2/x/claim/types"
)
// GetTxCmd returns the transaction commands for the module.
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("%s transaction subcommands", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand(
NewClaimCmd(),
)
return cmd
}
func NewClaimCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "claim [airdrop-id] [condition-type]",
Args: cobra.ExactArgs(2),
Short: "Claim the claimable amount with a condition type",
Long: strings.TrimSpace(
fmt.Sprintf(`Claim your claimable amount with a condition type.
Full allocation can be claimed by completing all tasks in core network activities.
There are 4 different tasks (condition types) and you must complete the task before claiming the amount.
Reference the spec docs to understand the mechanism.
Example:
$ %s tx %s claim 1 deposit --from mykey
$ %s tx %s claim 1 swap --from mykey
$ %s tx %s claim 1 liquidstake --from mykey
$ %s tx %s claim 1 vote --from mykey
`,
version.AppName, types.ModuleName,
version.AppName, types.ModuleName,
version.AppName, types.ModuleName,
version.AppName, types.ModuleName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
airdropId, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}
condType := NormalizeConditionType(args[1])
if condType == types.ConditionTypeUnspecified {
return fmt.Errorf("unknown condition type %s", args[0])
}
msg := types.NewMsgClaim(
airdropId,
clientCtx.GetFromAddress(),
condType,
)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}