-
Notifications
You must be signed in to change notification settings - Fork 13
/
query.go
768 lines (678 loc) · 20.7 KB
/
query.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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
package cli
import (
"encoding/json"
"fmt"
"strconv"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
gethCommon "github.com/ethereum/go-ethereum/common"
abcitype "github.com/tendermint/tendermint/abci/types"
types2 "github.com/functionx/fx-core/x/ibc/applications/transfer/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
"github.com/functionx/fx-core/x/crosschain/types"
)
const (
flagChannelIBC = "channelIBC"
)
func GetQueryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands from cross chain",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand([]*cobra.Command{
// query module params
CmdGetParams(),
// query Oracle
CmdGetOracles(),
CmdGetChainOracles(),
CmdGetOracleByAddr(),
CmdGetOracleByOrchestrator(),
CmdGetOracleByExternalAddr(),
// query oracle set
CmdGetCurrentOracleSet(),
CmdGetOracleSetRequest(),
// need oracle consensus sign
// 1. oracle set change confirm
CmdGetPendingOracleSetRequest(),
CmdGetOracleSetConfirm(),
CmdGetOracleSetConfirms(),
// 2. request batch confirm
CmdGetPendingOutgoingTXBatchRequest(),
CmdBatchConfirm(),
CmdBatchConfirms(),
// send to external
CmdGetPendingSendToExternal(),
CmdOutgoingTxBatches(),
CmdGetBatchFees(),
// denom <-> external token
CmdGetDenomToExternalToken(),
CmdGetExternalTokenToDenom(),
// 1. oracle event nonce
CmdGetValidatorEventNonce(),
// 2. event nonce block height
CmdGetValidatorEventBlockHeight(),
//
// 1. query external -> fx -> ibc transfer sequence block height
CmdIbcSequenceHeight(),
// help cmd.
CmdCovertBridgeToken(),
}...)
for _, command := range cmd.Commands() {
flags.AddQueryFlagsToCmd(command)
}
return cmd
}
func CmdGetParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params [chain-name]",
Short: "Query the current parameters information",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
chainName := args[0]
res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{ChainName: chainName})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdGetOracles() *cobra.Command {
cmd := &cobra.Command{
Use: "oracles [chain-name]",
Short: "Get Oracles",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.Oracles(cmd.Context(), &types.QueryOraclesRequest{
ChainName: args[0],
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdGetChainOracles() *cobra.Command {
cmd := &cobra.Command{
Use: "chain-oracles [chain-name]",
Short: "Get Oracles",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
req := abcitype.RequestQuery{
Data: types.KeyChainOracles,
Path: fmt.Sprintf("/store/%s/key", args[0]),
}
abciResp, err := clientCtx.QueryABCI(req)
if err != nil {
return err
}
var chainOracle2 types.ChainOracle
if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(abciResp.Value, &chainOracle2); err != nil {
return err
}
return clientCtx.PrintObjectLegacy(chainOracle2)
},
}
return cmd
}
func CmdGetOracleByAddr() *cobra.Command {
cmd := &cobra.Command{
Use: "oracle-by-addr [chain-name] [oracle-address]",
Short: "Get Oracle for a given oracle address",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
oracleAddress, err := sdk.AccAddressFromBech32(args[1])
if err != nil {
return err
}
req := &types.QueryOracleByAddrRequest{
OracleAddress: oracleAddress.String(),
ChainName: args[0],
}
res, err := queryClient.GetOracleByAddr(cmd.Context(), req)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdGetOracleByOrchestrator() *cobra.Command {
cmd := &cobra.Command{
Use: "oracle-by-orchestrator [chain-name] [orchestrator]",
Short: "Get Oracle for a given orchestrator",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
orchestratorAddress, err := sdk.AccAddressFromBech32(args[1])
if err != nil {
return err
}
req := &types.QueryOracleByOrchestratorRequest{
OrchestratorAddress: orchestratorAddress.String(),
ChainName: args[0],
}
res, err := queryClient.GetOracleByOrchestrator(cmd.Context(), req)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdGetOracleByExternalAddr() *cobra.Command {
cmd := &cobra.Command{
Use: "oracle-key-by-external-addr [chain-name] [external-address]",
Short: "query Oracle by external address",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
externalAddress := args[1]
if strings.HasPrefix(externalAddress, "0x") {
if !gethCommon.IsHexAddress(externalAddress) {
return fmt.Errorf("target address is invalid!address: [%s]", externalAddress)
}
externalAddress = gethCommon.HexToAddress(externalAddress).Hex()
}
res, err := queryClient.GetOracleByExternalAddr(cmd.Context(), &types.QueryOracleByExternalAddrRequest{
ExternalAddress: externalAddress,
ChainName: args[0],
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdGetCurrentOracleSet() *cobra.Command {
cmd := &cobra.Command{
Use: "current-oracle-set [chain-name]",
Short: "Query current oracle-set",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.CurrentOracleSet(cmd.Context(), &types.QueryCurrentOracleSetRequest{
ChainName: args[0],
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdGetOracleSetRequest() *cobra.Command {
cmd := &cobra.Command{
Use: "oracle-set-request [chain-name] [nonce]",
Short: "Get requested oracle-set with a particular nonce",
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
var nonce uint64
if len(args) == 1 {
queryAbciResp, err := clientCtx.QueryABCI(abcitype.RequestQuery{
Path: fmt.Sprintf("store/%s/key", args[0]),
Data: types.LatestOracleSetNonce,
})
if err != nil {
return err
}
nonce = types.UInt64FromBytes(queryAbciResp.Value)
if err = clientCtx.PrintString(fmt.Sprintf("latest oracle-set nonce:[%d]\n", nonce)); err != nil {
return err
}
} else {
var err error
nonce, err = strconv.ParseUint(args[1], 10, 64)
if err != nil {
return err
}
}
res, err := queryClient.OracleSetRequest(cmd.Context(), &types.QueryOracleSetRequestRequest{
ChainName: args[0],
Nonce: nonce,
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdGetPendingOracleSetRequest() *cobra.Command {
cmd := &cobra.Command{
Use: "pending-oracle-set-request [chain-name] [orchestrator]",
Short: "Get the latest oracle-set request which has not been signed by a particular oracle orchestrator",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
orchestratorAddress, err := sdk.AccAddressFromBech32(args[1])
if err != nil {
return err
}
req := &types.QueryLastPendingOracleSetRequestByAddrRequest{
OrchestratorAddress: orchestratorAddress.String(),
ChainName: args[0],
}
res, err := queryClient.LastPendingOracleSetRequestByAddr(cmd.Context(), req)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdGetOracleSetConfirm() *cobra.Command {
cmd := &cobra.Command{
Use: "oracle-set-confirm [chain-name] [nonce] [orchestrator]",
Short: "Get oracle-set confirmation with a particular nonce from a particular oracle orchestrator",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
nonce, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
return err
}
orchestratorAddress, err := sdk.AccAddressFromBech32(args[2])
if err != nil {
return err
}
res, err := queryClient.OracleSetConfirm(cmd.Context(), &types.QueryOracleSetConfirmRequest{
Nonce: nonce,
OrchestratorAddress: orchestratorAddress.String(),
ChainName: args[0],
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdGetOracleSetConfirms() *cobra.Command {
cmd := &cobra.Command{
Use: "oracle-set-confirms [chain-name] [nonce]",
Short: "Get oracle-set confirmations with a particular nonce",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
nonce, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
return err
}
res, err := queryClient.OracleSetConfirmsByNonce(cmd.Context(), &types.QueryOracleSetConfirmsByNonceRequest{
Nonce: nonce,
ChainName: args[0],
})
if err != nil {
return err
}
if err = clientCtx.PrintString(fmt.Sprintf("confirm size:[%d]\n", len(res.Confirms))); err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdGetPendingOutgoingTXBatchRequest() *cobra.Command {
cmd := &cobra.Command{
Use: "pending-batch-request [chain-name] [orchestrator]",
Short: "Get the latest outgoing TX batch request which has not been signed by a particular oracle orchestrator",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
orchestratorAddress, err := sdk.AccAddressFromBech32(args[1])
if err != nil {
return err
}
res, err := queryClient.LastPendingBatchRequestByAddr(cmd.Context(), &types.QueryLastPendingBatchRequestByAddrRequest{
OrchestratorAddress: orchestratorAddress.String(),
ChainName: args[0],
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdBatchConfirm() *cobra.Command {
cmd := &cobra.Command{
Use: "batch-confirm [chain-name] [token-contract] [nonce] [orchestrator]",
Short: "query outgoing tx batches confirm by oracle orchestrator",
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
tokenContract := args[1]
if strings.HasPrefix(tokenContract, "0x") {
if !gethCommon.IsHexAddress(tokenContract) {
return fmt.Errorf("contract address is invalid!address:[%s]", tokenContract)
}
tokenContract = gethCommon.HexToAddress(tokenContract).Hex()
}
nonce, err := strconv.ParseUint(args[2], 10, 64)
if err != nil {
return err
}
orchestratorAddress, err := sdk.AccAddressFromBech32(args[3])
if err != nil {
return err
}
res, err := queryClient.BatchConfirm(cmd.Context(), &types.QueryBatchConfirmRequest{
ChainName: args[0],
TokenContract: tokenContract,
Nonce: nonce,
OrchestratorAddress: orchestratorAddress.String(),
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdBatchConfirms() *cobra.Command {
cmd := &cobra.Command{
Use: "batch-confirms [chain-name] [token-contract] [nonce]",
Short: "query outgoing tx batches confirms",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
tokenContract := args[1]
if strings.HasPrefix(tokenContract, "0x") {
if !gethCommon.IsHexAddress(tokenContract) {
return fmt.Errorf("contract address is invalid!address:[%s]", tokenContract)
}
tokenContract = gethCommon.HexToAddress(tokenContract).Hex()
}
nonce, err := strconv.Atoi(args[2])
if err != nil {
return err
}
res, err := queryClient.BatchConfirms(cmd.Context(), &types.QueryBatchConfirmsRequest{
TokenContract: tokenContract,
Nonce: uint64(nonce),
ChainName: args[0],
})
if err != nil {
return err
}
if err = clientCtx.PrintString(fmt.Sprintf("confirm size:[%d]\n", len(res.Confirms))); err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdGetPendingSendToExternal() *cobra.Command {
cmd := &cobra.Command{
Use: "pending-send-to-external [chain-name] [fxAddr]",
Short: "query pending send to external txs",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
chainName := args[0]
if err := types.ValidateModuleName(chainName); err != nil {
return err
}
fxAddr := args[1]
if _, err := sdk.AccAddressFromBech32(fxAddr); err != nil {
return nil
}
res, err := queryClient.GetPendingSendToExternal(cmd.Context(), &types.QueryPendingSendToExternalRequest{
ChainName: chainName,
SenderAddress: fxAddr,
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdOutgoingTxBatches() *cobra.Command {
cmd := &cobra.Command{
Use: "outgoing-tx-batches [chain-name]",
Short: "query outgoing tx batches",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.OutgoingTxBatches(cmd.Context(), &types.QueryOutgoingTxBatchesRequest{
ChainName: args[0],
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdGetBatchFees() *cobra.Command {
cmd := &cobra.Command{
Use: "batch-fees [chain-name]",
Short: "Gets a list of send to external transaction fees to be processed",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.BatchFees(cmd.Context(), &types.QueryBatchFeeRequest{
ChainName: args[0],
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdGetDenomToExternalToken() *cobra.Command {
cmd := &cobra.Command{
Use: "external-token [chain-name] [denom]",
Short: "Query contract address from denom",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.DenomToToken(cmd.Context(), &types.QueryDenomToTokenRequest{
ChainName: args[0],
Denom: args[1],
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdGetExternalTokenToDenom() *cobra.Command {
cmd := &cobra.Command{
Use: "denom [chain-name] [token-address]",
Short: "Query denom from contract address",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
tokenAddress := args[1]
if strings.HasPrefix(tokenAddress, "0x") {
if !gethCommon.IsHexAddress(tokenAddress) {
return fmt.Errorf("invalid contract address:%s", tokenAddress)
}
tokenAddress = gethCommon.HexToAddress(tokenAddress).Hex()
}
res, err := queryClient.TokenToDenom(cmd.Context(), &types.QueryTokenToDenomRequest{
ChainName: args[0],
Token: tokenAddress,
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdGetValidatorEventNonce() *cobra.Command {
cmd := &cobra.Command{
Use: "event-nonce [chain-name] [orchestrator]",
Short: "query last event nonce by oracle orchestratorAddress",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
orchestratorAddress, err := sdk.AccAddressFromBech32(args[1])
if err != nil {
return err
}
res, err := queryClient.LastEventNonceByAddr(cmd.Context(), &types.QueryLastEventNonceByAddrRequest{
ChainName: args[0],
OrchestratorAddress: orchestratorAddress.String(),
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdGetValidatorEventBlockHeight() *cobra.Command {
cmd := &cobra.Command{
Use: "event-block-height [chain-name] [orchestrator]",
Short: "query last event block height by oracle orchestrator",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
orchestratorAddress, err := sdk.AccAddressFromBech32(args[1])
if err != nil {
return err
}
res, err := queryClient.LastEventBlockHeightByAddr(cmd.Context(), &types.QueryLastEventBlockHeightByAddrRequest{
OrchestratorAddress: orchestratorAddress.String(),
ChainName: args[0],
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdIbcSequenceHeight() *cobra.Command {
cmd := &cobra.Command{
Use: "ibc-sequence-height [chain-name] [sourcePort] [sourceChannel] [sequence]",
Short: "query ibc sequence block height",
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
sequence, err := strconv.ParseUint(args[3], 10, 64)
if err != nil {
return err
}
res, err := queryClient.GetIbcSequenceHeightByChannel(cmd.Context(), &types.QueryIbcSequenceHeightRequest{
ChainName: args[0],
SourcePort: args[1],
SourceChannel: args[2],
Sequence: sequence,
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
func CmdCovertBridgeToken() *cobra.Command {
cmd := &cobra.Command{
Use: "covert-bridge-token [chain-name] [tokenContract]",
Short: "covert bridge claim token name",
Example: "fxcored q crosschain covert-bridge-token bsc 0x3f6795b8ABE0775a88973469909adE1405f7ac09 --channelIBC=transfer/channel-0",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
chainName := args[0]
if err := types.ValidateModuleName(chainName); err != nil {
return err
}
tokenContract := args[1]
if err := types.ValidateExternalAddress(tokenContract); err != nil {
return err
}
channelIbc, err := cmd.Flags().GetString(flagChannelIBC)
if err != nil {
return err
}
coinName := fmt.Sprintf("%s%s", chainName, tokenContract)
if len(channelIbc) > 0 {
coinName = types2.DenomTrace{
Path: channelIbc,
BaseDenom: coinName,
}.IBCDenom()
}
type output struct {
ChainName string
TokenContract string
ChannelIbc string
CoinName string
}
indent, err := json.MarshalIndent(output{
ChainName: chainName,
TokenContract: tokenContract,
ChannelIbc: channelIbc,
CoinName: coinName,
}, "", " ")
if err != nil {
return err
}
return clientCtx.PrintBytes(indent)
},
}
cmd.Flags().String(flagChannelIBC, "", "bridge bind channel: transfer/channel-0")
return cmd
}