forked from crescent-network/crescent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx.go
86 lines (70 loc) · 2.04 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
package cli
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/jesse-pinkman-cre/crescent/x/referral/types"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
)
// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand(
GetAddReferralCmd(),
GetSetReferralCmd(),
)
return cmd
}
func GetAddReferralCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create-referral [code]",
Args: cobra.ExactArgs(1),
Short: "Create my referral code",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
//TODO JIHON: input validation
// coins, err := sdk.ParseCoinsNormalized(args[0])
// if err != nil {
// return fmt.Errorf("invalid coins: %w", err)
// }
code := args[0]
msg := types.NewMsgAddReferral(clientCtx.GetFromAddress(), code)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
func GetSetReferralCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "set-parent [parent]",
Args: cobra.ExactArgs(1),
Short: "Set my parent code",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
//TODO JIHON: input validation
// coins, err := sdk.ParseCoinsNormalized(args[0])
// if err != nil {
// return fmt.Errorf("invalid coins: %w", err)
// }
parent := args[0]
msg := types.NewMsgSetReferral(clientCtx.GetFromAddress(), parent)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}