-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
flags.go
340 lines (301 loc) · 11.7 KB
/
flags.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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
package cmd
import (
"fmt"
"time"
"github.com/cosmos/relayer/v2/relayer"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
const (
flagHome = "home"
flagURL = "url"
flagSkip = "skip"
flagTimeout = "timeout"
flagJSON = "json"
flagYAML = "yaml"
flagFile = "file"
flagPath = "path"
flagMaxTxSize = "max-tx-size"
flagMaxMsgLength = "max-msgs"
flagIBCDenoms = "ibc-denoms"
flagTimeoutHeightOffset = "timeout-height-offset"
flagTimeoutTimeOffset = "timeout-time-offset"
flagMaxRetries = "max-retries"
flagThresholdTime = "time-threshold"
flagUpdateAfterExpiry = "update-after-expiry"
flagUpdateAfterMisbehaviour = "update-after-misbehaviour"
flagClientTrustingPeriod = "client-tp"
flagOverride = "override"
flagSrcPort = "src-port"
flagDstPort = "dst-port"
flagOrder = "order"
flagVersion = "version"
flagDebugAddr = "debug-addr"
flagOverwriteConfig = "overwrite"
flagLimit = "limit"
flagHeight = "height"
flagPage = "page"
flagPageKey = "page-key"
flagCountTotal = "count-total"
flagReverse = "reverse"
flagProcessor = "processor"
flagInitialBlockHistory = "block-history"
flagMemo = "memo"
flagFilterRule = "filter-rule"
flagFilterChannels = "filter-channels"
)
const (
// 7597 is "RLYR" on a telephone keypad.
// It also happens to be unassigned in the IANA port list.
defaultDebugAddr = "localhost:7597"
)
func ibcDenomFlags(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().BoolP(flagIBCDenoms, "i", false, "Display IBC denominations for sending tokens back to other chains")
if err := v.BindPFlag(flagIBCDenoms, cmd.Flags().Lookup(flagIBCDenoms)); err != nil {
panic(err)
}
return cmd
}
func heightFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().Int64(flagHeight, 0, "Height of headers to fetch")
if err := v.BindPFlag(flagHeight, cmd.Flags().Lookup(flagHeight)); err != nil {
panic(err)
}
return cmd
}
func paginationFlags(v *viper.Viper, cmd *cobra.Command, query string) *cobra.Command {
cmd.Flags().Uint64(flagPage, 1, fmt.Sprintf("pagination page of %s to query for. This sets offset to a multiple of limit", query))
cmd.Flags().String(flagPageKey, "", fmt.Sprintf("pagination page-key of %s to query for", query))
cmd.Flags().Uint64(flagLimit, 100, fmt.Sprintf("pagination limit of %s to query for", query))
cmd.Flags().Bool(flagCountTotal, false, fmt.Sprintf("count total number of records in %s to query for", query))
cmd.Flags().Bool(flagReverse, false, "results are sorted in descending order")
if err := v.BindPFlag(flagPage, cmd.Flags().Lookup(flagPage)); err != nil {
panic(err)
}
if err := v.BindPFlag(flagPageKey, cmd.Flags().Lookup(flagPageKey)); err != nil {
panic(err)
}
if err := v.BindPFlag(flagLimit, cmd.Flags().Lookup(flagLimit)); err != nil {
panic(err)
}
if err := v.BindPFlag(flagCountTotal, cmd.Flags().Lookup(flagCountTotal)); err != nil {
panic(err)
}
if err := v.BindPFlag(flagReverse, cmd.Flags().Lookup(flagReverse)); err != nil {
panic(err)
}
return cmd
}
func yamlFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().BoolP(flagYAML, "y", false, "output using yaml")
if err := v.BindPFlag(flagYAML, cmd.Flags().Lookup(flagYAML)); err != nil {
panic(err)
}
return cmd
}
func skipConfirm(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().BoolP(flagSkip, "y", false, "output using yaml")
if err := v.BindPFlag(flagSkip, cmd.Flags().Lookup(flagSkip)); err != nil {
panic(err)
}
return cmd
}
func chainsAddFlags(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
fileFlag(v, cmd)
urlFlag(v, cmd)
return cmd
}
func pathFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(flagPath, "p", "", "specify the path to relay over")
if err := v.BindPFlag(flagPath, cmd.Flags().Lookup(flagPath)); err != nil {
panic(err)
}
return cmd
}
func timeoutFlags(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().Uint64P(flagTimeoutHeightOffset, "y", 0, "set timeout height offset")
cmd.Flags().DurationP(flagTimeoutTimeOffset, "c", time.Duration(0), "set timeout time offset")
if err := v.BindPFlag(flagTimeoutHeightOffset, cmd.Flags().Lookup(flagTimeoutHeightOffset)); err != nil {
panic(err)
}
if err := v.BindPFlag(flagTimeoutTimeOffset, cmd.Flags().Lookup(flagTimeoutTimeOffset)); err != nil {
panic(err)
}
return cmd
}
func jsonFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().BoolP(flagJSON, "j", false, "returns the response in json format")
if err := v.BindPFlag(flagJSON, cmd.Flags().Lookup(flagJSON)); err != nil {
panic(err)
}
return cmd
}
func fileFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(flagFile, "f", "", "fetch json data from specified file")
if err := v.BindPFlag(flagFile, cmd.Flags().Lookup(flagFile)); err != nil {
panic(err)
}
return cmd
}
func pathFilterFlags(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().String(flagFilterRule, "", `filter rule ("allowlist", "denylist", or "" for no filtering)`)
if err := v.BindPFlag(flagFilterRule, cmd.Flags().Lookup(flagFilterRule)); err != nil {
panic(err)
}
cmd.Flags().String(flagFilterChannels, "", "channels from source chain perspective to filter")
if err := v.BindPFlag(flagFilterRule, cmd.Flags().Lookup(flagFilterRule)); err != nil {
panic(err)
}
return cmd
}
func timeoutFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(flagTimeout, "t", "10s", "timeout between relayer runs")
if err := v.BindPFlag(flagTimeout, cmd.Flags().Lookup(flagTimeout)); err != nil {
panic(err)
}
return cmd
}
func getTimeout(cmd *cobra.Command) (time.Duration, error) {
to, err := cmd.Flags().GetString(flagTimeout)
if err != nil {
return 0, err
}
return time.ParseDuration(to)
}
func urlFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(flagURL, "u", "", "url to fetch data from")
if err := v.BindPFlag(flagURL, cmd.Flags().Lookup(flagURL)); err != nil {
panic(err)
}
return cmd
}
func strategyFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(flagMaxTxSize, "s", "2", "strategy of path to generate of the messages in a relay transaction")
cmd.Flags().StringP(flagMaxMsgLength, "l", "5", "maximum number of messages in a relay transaction")
if err := v.BindPFlag(flagMaxTxSize, cmd.Flags().Lookup(flagMaxTxSize)); err != nil {
panic(err)
}
if err := v.BindPFlag(flagMaxMsgLength, cmd.Flags().Lookup(flagMaxMsgLength)); err != nil {
panic(err)
}
return cmd
}
func getAddInputs(cmd *cobra.Command) (file string, url string, err error) {
file, err = cmd.Flags().GetString(flagFile)
if err != nil {
return
}
url, err = cmd.Flags().GetString(flagURL)
if err != nil {
return
}
if file != "" && url != "" {
return "", "", errMultipleAddFlags
}
return
}
func retryFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().Uint64P(flagMaxRetries, "r", 3, "maximum retries after failed message send")
if err := v.BindPFlag(flagMaxRetries, cmd.Flags().Lookup(flagMaxRetries)); err != nil {
panic(err)
}
return cmd
}
func updateTimeFlags(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().Duration(flagThresholdTime, relayer.DefaultClientUpdateThreshold, "time after previous client update before automatic client update")
if err := v.BindPFlag(flagThresholdTime, cmd.Flags().Lookup(flagThresholdTime)); err != nil {
panic(err)
}
return cmd
}
func clientParameterFlags(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().BoolP(flagUpdateAfterExpiry, "e", true,
"allow governance to update the client if expiry occurs")
cmd.Flags().BoolP(flagUpdateAfterMisbehaviour, "m", true,
"allow governance to update the client if misbehaviour freezing occurs")
cmd.Flags().Duration(flagClientTrustingPeriod, 0, "custom light client trusting period ex. 24h (default: 85% of chains reported unbonding time)")
if err := v.BindPFlag(flagUpdateAfterExpiry, cmd.Flags().Lookup(flagUpdateAfterExpiry)); err != nil {
panic(err)
}
if err := v.BindPFlag(flagUpdateAfterMisbehaviour, cmd.Flags().Lookup(flagUpdateAfterMisbehaviour)); err != nil {
panic(err)
}
if err := v.BindPFlag(flagClientTrustingPeriod, cmd.Flags().Lookup(flagClientTrustingPeriod)); err != nil {
panic(err)
}
return cmd
}
func channelParameterFlags(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
return srcPortFlag(v, dstPortFlag(v, versionFlag(v, orderFlag(v, cmd))))
}
func overrideFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().Bool(flagOverride, false, "option to not reuse existing client or channel")
if err := v.BindPFlag(flagOverride, cmd.Flags().Lookup(flagOverride)); err != nil {
panic(err)
}
return cmd
}
func orderFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(flagOrder, "o", "unordered", "order of channel to create (ordered or unordered)")
if err := v.BindPFlag(flagOrder, cmd.Flags().Lookup(flagOrder)); err != nil {
panic(err)
}
return cmd
}
func versionFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(flagVersion, "v", "ics20-1", "version of channel to create")
if err := v.BindPFlag(flagVersion, cmd.Flags().Lookup(flagVersion)); err != nil {
panic(err)
}
return cmd
}
func srcPortFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().String(flagSrcPort, "transfer", "port on src chain to use when generating path")
if err := v.BindPFlag(flagSrcPort, cmd.Flags().Lookup(flagSrcPort)); err != nil {
panic(err)
}
return cmd
}
func dstPortFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().String(flagDstPort, "transfer", "port on dst chain to use when generating path")
if err := v.BindPFlag(flagDstPort, cmd.Flags().Lookup(flagDstPort)); err != nil {
panic(err)
}
return cmd
}
func debugServerFlags(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().String(flagDebugAddr, defaultDebugAddr, "address to use for debug server. Set empty to disable debug server.")
if err := v.BindPFlag(flagDebugAddr, cmd.Flags().Lookup(flagDebugAddr)); err != nil {
panic(err)
}
return cmd
}
func processorFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(flagProcessor, "p", relayer.ProcessorEvents, "which relayer processor to use")
if err := v.BindPFlag(flagProcessor, cmd.Flags().Lookup(flagProcessor)); err != nil {
panic(err)
}
return cmd
}
func initBlockFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().Uint64P(flagInitialBlockHistory, "b", 20, "initial block history to query when using 'events' as the processor for relaying")
if err := v.BindPFlag(flagInitialBlockHistory, cmd.Flags().Lookup(flagInitialBlockHistory)); err != nil {
panic(err)
}
return cmd
}
func memoFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().String(flagMemo, "", "a memo to include in relayed packets")
if err := v.BindPFlag(flagMemo, cmd.Flags().Lookup(flagMemo)); err != nil {
panic(err)
}
return cmd
}
func OverwriteConfigFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().BoolP(flagOverwriteConfig, "o", false,
"overwrite already configured paths - will clear channel filter(s)")
if err := v.BindPFlag(flagOverwriteConfig, cmd.Flags().Lookup(flagOverwriteConfig)); err != nil {
panic(err)
}
return cmd
}