-
Notifications
You must be signed in to change notification settings - Fork 10
/
cmd.go
278 lines (238 loc) · 7.64 KB
/
cmd.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package main
import (
"fmt"
"github.com/spf13/cobra"
)
// VERSION TODO: something more intelligent
// Remember to change this every time ...
const VERSION = "0.4.2"
var rootCmd = &cobra.Command{
Use: "multisig",
Short: "manage multisig transactions",
Version: VERSION,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}
var txCmd = &cobra.Command{
Use: "tx",
Short: "generate a new unsigned tx",
// Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}
var pushCmd = &cobra.Command{
Use: "push <unsigned tx file> <chain name> <key name>",
Short: "push the given unsigned tx with associated signing metadata",
Long: "if a tx already exists for this chain and key, it will start using prefixes",
Args: cobra.ExactArgs(3),
RunE: cmdPush,
}
var authzCmd = &cobra.Command{
Use: "authz",
Short: "generate an unsigned authz tx grant",
Args: cobra.NoArgs, // print long help from custom verification
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}
var authzGrantCmd = &cobra.Command{
Use: "grant <chain name> <key name> <grantee address> <withdraw|commission|delegate|vote|unbond|redelegate> <expiration days>",
Short: "generate an authz grant tx and push it",
Long: "\nThis commands allows you to generate an unsigned tx to grant authorization " +
"to a 'grantee' address that will be able to execute transactions as specified in " +
"the '<message-type>' parameter. The grant authz is the first step in order to " +
"authorize, after the grant tx is signed, then an 'authz exec' command will need to " +
"be signed and executed in order to enable the authorization on chain.\n" +
"Example: Grant withdraw authz permissions to a grantee (cosmos1add... address) for 30 days\n" +
"multisig tx grant cosmoshub my-key cosmos1adggsadfsadfffredffdssdf withdraw 30",
Args: func(cmd *cobra.Command, args []string) error {
numArgs := 5 // Update the number of arguments if command use changes
if len(args) != numArgs {
cmd.Help()
return fmt.Errorf("\n accepts %d arg(s), received %d", numArgs, len(args))
}
return nil
},
SilenceUsage: true,
SilenceErrors: true,
RunE: cmdGrantAuthz,
}
var authzRevokeCmd = &cobra.Command{
Use: "revoke <chain name> <key name> <grantee address> <withdraw|commission|delegate|vote|unbond|redelegate>",
Short: "generate an authz revoke tx and push it",
Long: "\nThis commands allows you to generate an unsigned tx to revoke an existing authorization " +
"to a 'grantee' address for a particular '<message-type>' (e.g. withdraw)\n " +
"multisig tx revoke cosmoshub my-key cosmos1adggsadfsadfffredffdssdf withdraw",
Args: func(cmd *cobra.Command, args []string) error {
numArgs := 4 // Update the number of arguments if command use changes
if len(args) != numArgs {
cmd.Help()
return fmt.Errorf("\n accepts %d arg(s), received %d", numArgs, len(args))
}
return nil
},
SilenceUsage: true,
SilenceErrors: true,
RunE: cmdRevokeAuthz,
}
var voteCmd = &cobra.Command{
Use: "vote <chain name> <key name> <proposal number> <vote option (yes/no/veto/abstain)>",
Short: "generate a vote tx and push it",
Args: cobra.ExactArgs(4),
RunE: cmdVote,
}
var withdrawCmd = &cobra.Command{
Use: "withdraw <chain name> <key name>",
Short: "generate a withdraw-all-rewards tx and push it",
Args: cobra.ExactArgs(2),
RunE: cmdWithdraw,
}
var delegateCmd = &cobra.Command{
Use: "delegate <chain name> <key name> <validator_address> <amount>",
Short: "generate a delegate tx and push it",
Args: cobra.ExactArgs(4),
RunE: cmdDelegate,
}
var claimValidatorCmd = &cobra.Command{
Use: "claim-validator <chain name> <key name> <validator_address>",
Short: "generate a withdraw-rewards tx to claim validators rewards and commission and push it",
Args: cobra.ExactArgs(3),
RunE: cmdClaimValidator,
}
var signCmd = &cobra.Command{
Use: "sign <chain name> <key name>",
Short: "sign a tx",
Args: cobra.ExactArgs(2),
RunE: cmdSign,
}
var listCmd = &cobra.Command{
Use: "list <chain name> <key name>",
Short: "list items in a directory",
Args: cobra.MaximumNArgs(2),
RunE: cmdList,
}
var broadcastCmd = &cobra.Command{
Use: "broadcast <chain name> <key name>",
Short: "broadcast a tx",
Args: cobra.ExactArgs(2),
RunE: cmdBroadcast,
}
var deleteCmd = &cobra.Command{
Use: "delete <chain name> <key name>",
Short: "delete a tx",
Args: cobra.ExactArgs(2),
RunE: cmdDelete,
}
var rawCmd = &cobra.Command{
Use: "raw <cmd>",
Short: "raw operations on the s3 bucket",
}
var rawBech32Cmd = &cobra.Command{
Use: "bech32 <bech32 string> <new prefix>",
Short: "convert a bech32 string to a different prefix",
Args: cobra.ExactArgs(2),
RunE: cmdRawBech32,
}
var rawCatCmd = &cobra.Command{
Use: "cat <chain name> <key name>",
Short: "dump the contents of all files in a directory",
Args: cobra.ExactArgs(2),
RunE: cmdRawCat,
}
var rawUpCmd = &cobra.Command{
Use: "up <source filepath> <destination filepath>",
Short: "upload a local file to a path in the s3 bucket",
Args: cobra.ExactArgs(2),
RunE: cmdRawUp,
}
var rawDownCmd = &cobra.Command{
Use: "down <source filepath> <destination filepath>",
Short: "download a file or directory from the s3 bucket",
Long: "if the path ends in a '/' it will attempt to download all files in that directory",
Args: cobra.ExactArgs(2),
RunE: cmdRawDown,
}
var rawMkdirCmd = &cobra.Command{
Use: "mkdir <directory path>",
Short: "create a directory in the s3 bucket - must end with a '/'",
Long: "if the path ends in a '/' it will attempt to download all files in that directory",
Args: cobra.ExactArgs(1),
RunE: cmdRawMkdir,
}
var rawDeleteCmd = &cobra.Command{
Use: "delete <filepath>",
Short: "delete a file from the s3 bucket",
Args: cobra.ExactArgs(1),
RunE: cmdRawDelete,
}
var (
flagTx string
flagSequence int
flagAccount int
flagNode string
flagFrom string
flagAll bool
flagForce bool
flagAdditional bool
flagDescription string
flagDenom string
flagTxIndex int
flagConfigPath string
flagGas int
flagFees string
flagMultisigKey string
flagHomePath string
)
func init() {
// Main commands
rootCmd.AddCommand(txCmd)
rootCmd.AddCommand(signCmd)
rootCmd.AddCommand(listCmd)
rootCmd.AddCommand(broadcastCmd)
rootCmd.AddCommand(rawCmd)
rootCmd.AddCommand(deleteCmd)
// Raw commands
rawCmd.AddCommand(rawBech32Cmd)
rawCmd.AddCommand(rawCatCmd)
rawCmd.AddCommand(rawUpCmd)
rawCmd.AddCommand(rawDownCmd)
rawCmd.AddCommand(rawMkdirCmd)
rawCmd.AddCommand(rawDeleteCmd)
// Tx subcommands
txCmd.AddCommand(pushCmd)
txCmd.AddCommand(voteCmd)
txCmd.AddCommand(withdrawCmd)
txCmd.AddCommand(authzCmd)
txCmd.AddCommand(claimValidatorCmd)
txCmd.AddCommand(delegateCmd)
// Authz subcommands
authzCmd.AddCommand(authzGrantCmd)
authzCmd.AddCommand(authzRevokeCmd)
// Add flags to commands
addTxCmdCommonFlags(pushCmd)
addTxCmdCommonFlags(voteCmd)
addTxCmdGasFeesFlags(voteCmd)
addDenomFlags(voteCmd)
addTxCmdCommonFlags(withdrawCmd)
addTxCmdGasFeesFlags(withdrawCmd)
addDenomFlags(withdrawCmd)
addTxCmdCommonFlags(claimValidatorCmd)
addTxCmdGasFeesFlags(claimValidatorCmd)
addDenomFlags(claimValidatorCmd)
addTxCmdCommonFlags(delegateCmd)
addTxCmdGasFeesFlags(delegateCmd)
addDenomFlags(delegateCmd)
addTxCmdCommonFlags(authzGrantCmd)
addTxCmdGasFeesFlags(authzGrantCmd)
addDenomFlags(authzGrantCmd)
addTxCmdCommonFlags(authzRevokeCmd)
addTxCmdGasFeesFlags(authzRevokeCmd)
addDenomFlags(authzRevokeCmd)
addSignCmdFlags(signCmd)
addListCmdFlags(listCmd)
addBroadcastCmdFlags(broadcastCmd)
addDeleteCmdFlags(deleteCmd)
addGlobalFlags(rootCmd)
}