-
Notifications
You must be signed in to change notification settings - Fork 44
/
tx.go
169 lines (137 loc) · 4.94 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package cli
import (
"fmt"
"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/spf13/cobra"
subspacestypes "github.com/desmos-labs/desmos/v3/x/subspaces/types"
"github.com/desmos-labs/desmos/v3/x/relationships/types"
)
// NewTxCmd returns a new command allowing to perform profiles transactions
func NewTxCmd() *cobra.Command {
profileTxCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Relationships transaction subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
profileTxCmd.AddCommand(
GetCmdCreateRelationship(),
GetCmdDeleteRelationship(),
GetCmdBlockUser(),
GetCmdUnblockUser(),
)
return profileTxCmd
}
// GetCmdCreateRelationship returns the command allowing to create a relationship
func GetCmdCreateRelationship() *cobra.Command {
cmd := &cobra.Command{
Use: "create-relationship [counterparty] [subspace-id]",
Short: "Create a relationship with the given receiver address",
Example: fmt.Sprintf(`%s tx relationships create-relationship desmos1e209r8nc8qdkmqujahwrq4xrlxhk3fs9k7yzmw 1`, version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
subspaceID, err := subspacestypes.ParseSubspaceID(args[1])
if err != nil {
return err
}
msg := types.NewMsgCreateRelationship(clientCtx.FromAddress.String(), args[0], subspaceID)
if err = msg.ValidateBasic(); err != nil {
return fmt.Errorf("message validation failed: %w", err)
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdDeleteRelationship returns the command allowing to delete a relationships
func GetCmdDeleteRelationship() *cobra.Command {
cmd := &cobra.Command{
Use: "delete-relationship [counterparty] [subspace-id]",
Short: "Delete the relationship with the given user",
Example: fmt.Sprintf(`%s tx relationships delete-relationship desmos1e209r8nc8qdkmqujahwrq4xrlxhk3fs9k7yzmw 1`, version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
subspaceID, err := subspacestypes.ParseSubspaceID(args[1])
if err != nil {
return err
}
msg := types.NewMsgDeleteRelationship(clientCtx.FromAddress.String(), args[0], subspaceID)
if err = msg.ValidateBasic(); err != nil {
return fmt.Errorf("message validation failed: %w", err)
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdBlockUser returns the command allowing to block a user
func GetCmdBlockUser() *cobra.Command {
cmd := &cobra.Command{
Use: "block [address] [subspace] [[reason]]",
Short: "Block the user with the given address, optionally specifying the reason for the block",
Example: fmt.Sprintf(`%s tx relationships block desmos13p5pamrljhza3fp4es5m3llgmnde5fzcpq6nud 1
%s tx relationships block desmos13p5pamrljhza3fp4es5m3llgmnde5fzcpq6nud 1 "reason for block"`, version.AppName, version.AppName),
Args: cobra.RangeArgs(2, 3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
subspaceID, err := subspacestypes.ParseSubspaceID(args[1])
if err != nil {
return err
}
reason := ""
if len(args) == 3 {
reason = args[2]
}
msg := types.NewMsgBlockUser(clientCtx.FromAddress.String(), args[0], reason, subspaceID)
if err = msg.ValidateBasic(); err != nil {
return fmt.Errorf("message validation failed: %w", err)
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdUnblockUser returns the command allowing to unblock a user
func GetCmdUnblockUser() *cobra.Command {
cmd := &cobra.Command{
Use: "unblock [address] [subspace]",
Short: "Unblock the user with the given address",
Example: fmt.Sprintf(`%s tx relationships unblock desmos13p5pamrljhza3fp4es5m3llgmnde5fzcpq6nud 1`, version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
subspaceID, err := subspacestypes.ParseSubspaceID(args[1])
if err != nil {
return err
}
msg := types.NewMsgUnblockUser(clientCtx.FromAddress.String(), args[0], subspaceID)
if err = msg.ValidateBasic(); err != nil {
return fmt.Errorf("message validation failed: %w", err)
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}