-
Notifications
You must be signed in to change notification settings - Fork 36
/
tx.go
1263 lines (1126 loc) · 43.2 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
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
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package cli
import (
"errors"
"fmt"
"strconv"
"strings"
"time"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
cerrs "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkErrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/version"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/authz"
"github.com/cosmos/cosmos-sdk/x/feegrant"
govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types"
channelutils "github.com/cosmos/ibc-go/v6/modules/core/04-channel/client/utils"
attrcli "github.com/provenance-io/provenance/x/attribute/client/cli"
"github.com/provenance-io/provenance/x/marker/types"
)
const (
FlagType = "type"
FlagSupplyFixed = "supplyFixed"
FlagAllowGovernanceControl = "allowGovernanceControl"
FlagTransferLimit = "transfer-limit"
FlagExpiration = "expiration"
FlagPeriod = "period"
FlagPeriodLimit = "period-limit"
FlagSpendLimit = "spend-limit"
FlagAllowList = "allow-list"
FlagAllowedMsgs = "allowed-messages"
FlagPacketTimeoutHeight = "packet-timeout-height"
FlagPacketTimeoutTimestamp = "packet-timeout-timestamp"
FlagAbsoluteTimeouts = "absolute-timeouts"
FlagMemo = "memo"
FlagRequiredAttributes = "required-attributes"
FlagAllowForceTransfer = "allow-force-transfer"
FlagAdd = "add"
FlagRemove = "remove"
FlagGovProposal = "gov-proposal"
FlagUsdMills = "usd-mills"
FlagVolume = "volume"
)
// NewTxCmd returns the top-level command for marker CLI transactions.
func NewTxCmd() *cobra.Command {
txCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Transaction commands for the marker module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
txCmd.AddCommand(
GetCmdFinalize(),
GetCmdActivate(),
GetCmdCancel(),
GetCmdDelete(),
GetCmdMint(),
GetCmdBurn(),
GetCmdAddAccess(),
GetCmdDeleteAccess(),
GetCmdWithdrawCoins(),
GetNewTransferCmd(),
GetCmdAddMarker(),
GetCmdMarkerProposal(),
GetCmdGrantAuthorization(),
GetCmdRevokeAuthorization(),
GetCmdFeeGrant(),
GetIbcTransferTxCmd(),
GetCmdAddFinalizeActivateMarker(),
GetCmdUpdateRequiredAttributes(),
GetCmdUpdateForcedTransfer(),
GetCmdSetAccountData(),
GetCmdUpdateSendDenyListRequest(),
GetCmdAddNetAssetValues(),
)
return txCmd
}
// GetCmdMarkerProposal returns a cmd for creating/submitting marker governance proposals
func GetCmdMarkerProposal() *cobra.Command {
cmd := &cobra.Command{
Use: "proposal [type] [proposal-file] [deposit]",
Args: cobra.ExactArgs(3),
Short: "Submit a marker proposal along with an initial deposit",
Long: strings.TrimSpace(`This command has been deprecated, and is no longer functional.
Please use 'gov proposal submit-proposal instead.
`,
),
RunE: func(cmd *cobra.Command, args []string) error {
return fmt.Errorf("this command has been deprecated, and is no longer functional. Please use 'gov proposal submit-proposal' instead")
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdAddMarker implements the create marker command
func GetCmdAddMarker() *cobra.Command {
cmd := &cobra.Command{
Use: "new [coin]",
Aliases: []string{"n"},
Args: cobra.ExactArgs(1),
Short: "Create a new marker",
Long: strings.TrimSpace(`Creates a new marker in the Proposed state managed by the from address
with the given supply amount and denomination provided in the coin argument
`),
Example: fmt.Sprintf(`$ %s tx marker new 1000hotdogcoin --%s=false --%s=false --from=mykey --%s=attr.one,*.attr.two,...`,
FlagType,
FlagSupplyFixed,
FlagAllowGovernanceControl,
FlagRequiredAttributes,
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
coin, err := sdk.ParseCoinNormalized(args[0])
if err != nil {
return fmt.Errorf("invalid coin %s", args[0])
}
callerAddr := clientCtx.GetFromAddress()
flagVals, err := ParseNewMarkerFlags(cmd)
if err != nil {
return err
}
msg := types.NewMsgAddMarkerRequest(
coin.Denom,
coin.Amount,
callerAddr,
callerAddr,
flagVals.MarkerType,
flagVals.SupplyFixed,
flagVals.AllowGovControl,
flagVals.AllowForceTransfer,
flagVals.RequiredAttributes,
flagVals.UsdMills,
flagVals.Volume,
)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
AddNewMarkerFlags(cmd)
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdMint implements the mint additional supply for marker command.
func GetCmdMint() *cobra.Command {
cmd := &cobra.Command{
Use: "mint [coin]",
Aliases: []string{"m"},
Args: cobra.ExactArgs(1),
Short: "Mint coins against the marker",
Long: strings.TrimSpace(`Mints coins of the marker's denomination and places them
in the marker's account under escrow. Caller must possess the mint permission and
marker must be in the active status.`),
Example: fmt.Sprintf(`$ %s tx marker mint 1000hotdogcoin --from mykey`, version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
coin, err := sdk.ParseCoinNormalized(args[0])
if err != nil {
return sdkErrors.ErrInvalidCoins.Wrapf("invalid coin %s", args[0])
}
callerAddr := clientCtx.GetFromAddress()
msg := types.NewMsgMintRequest(callerAddr, coin)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdBurn implements the burn coin supply from marker command.
func GetCmdBurn() *cobra.Command {
cmd := &cobra.Command{
Use: "burn [coin]",
Aliases: []string{"b"},
Args: cobra.ExactArgs(1),
Short: "Burn coins from the marker",
Long: strings.TrimSpace(`Burns the number of coins specified from the marker associated
with the coin's denomination. Only coins held in the marker's account may be burned. Caller
must possess the burn permission. Use the bank send operation to transfer coin into the marker
for burning. Marker must be in the active status to burn coin.`),
Example: fmt.Sprintf(`$ %s tx marker burn 1000hotdogcoin --from mykey`, version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
coin, err := sdk.ParseCoinNormalized(args[0])
if err != nil {
return sdkErrors.ErrInvalidCoins.Wrapf("invalid coin %s", args[0])
}
callerAddr := clientCtx.GetFromAddress()
msg := types.NewMsgBurnRequest(callerAddr, coin)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdFinalize implements the finalize marker command.
func GetCmdFinalize() *cobra.Command {
cmd := &cobra.Command{
Use: "finalize [denom]",
Aliases: []string{"f"},
Args: cobra.ExactArgs(1),
Short: "Finalize the marker account",
Long: strings.TrimSpace(`Finalize a marker identified by the given denomination. Only
the marker manager may finalize a marker. Once finalized callers who have been assigned
permission may perform mint,burn, or grant operations. Only the manager may activate the marker.`),
Example: fmt.Sprintf(`$ %s tx marker finalize hotdogcoin --from mykey`, version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
callerAddr := clientCtx.GetFromAddress()
msg := types.NewMsgFinalizeRequest(args[0], callerAddr)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdActivate implements the activate marker command.
func GetCmdActivate() *cobra.Command {
cmd := &cobra.Command{
Use: "activate [denom]",
Aliases: []string{"a"},
Args: cobra.ExactArgs(1),
Short: "Activate the marker account",
Long: strings.TrimSpace(`Activate a marker identified by the given denomination. Only
the marker manager may activate a marker. Once activated any total supply less than the
amount in circulation will be minted. Invariant checks will be enforced.`),
Example: fmt.Sprintf(`$ %s tx marker activate hotdogcoin --from mykey`, version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
callerAddr := clientCtx.GetFromAddress()
msg := types.NewMsgActivateRequest(args[0], callerAddr)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdCancel implements the cancel marker command.
func GetCmdCancel() *cobra.Command {
cmd := &cobra.Command{
Use: "cancel [denom]",
Aliases: []string{"c"},
Args: cobra.ExactArgs(1),
Short: "Cancel the marker account",
Example: fmt.Sprintf(`$ %s tx marker cancel hotdogcoin --from mykey`, version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
callerAddr := clientCtx.GetFromAddress()
msg := types.NewMsgCancelRequest(args[0], callerAddr)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdDelete implements the destroy marker command.
func GetCmdDelete() *cobra.Command {
cmd := &cobra.Command{
Use: "destroy [denom]",
Aliases: []string{"d"},
Args: cobra.ExactArgs(1),
Short: "Mark the marker for deletion",
Example: fmt.Sprintf(`$ %s tx marker destroy hotdogcoin --from mykey`, version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
callerAddr := clientCtx.GetFromAddress()
msg := types.NewMsgDeleteRequest(args[0], callerAddr)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdAddAccess implements the delegate access to a marker command.
func GetCmdAddAccess() *cobra.Command {
cmd := &cobra.Command{
Use: "grant [address] [denom] [permission]",
Aliases: []string{"g"},
Args: cobra.ExactArgs(3),
Short: "Grant access to a marker for the address coins from the marker",
Long: strings.TrimSpace(`Grant administrative access to a marker. From Address must have appropriate
existing access. Permissions are appended to any existing access grant. Valid permissions
are one of [mint, burn, deposit, withdraw, delete, admin, transfer].`),
Example: fmt.Sprintf(`$ %s tx marker grant pb1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj coindenom burn --from mykey`, version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
targetAddr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return cerrs.Wrapf(err, "grant for invalid address %s", args[0])
}
grant := types.NewAccessGrant(targetAddr, types.AccessListByNames(args[2]))
if err = grant.Validate(); err != nil {
return cerrs.Wrapf(err, "invalid access grant permission: %s", args[2])
}
callerAddr := clientCtx.GetFromAddress()
msg := types.NewMsgAddAccessRequest(args[1], callerAddr, *grant)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdDeleteAccess implements the revoke administrative access for a marker command.
func GetCmdDeleteAccess() *cobra.Command {
cmd := &cobra.Command{
Use: "revoke [address] [denom]",
Aliases: []string{"r"},
Args: cobra.ExactArgs(2),
Short: "Revoke all access to a marker for the address",
Long: strings.TrimSpace(`Revoke all administrative access to a marker for given access.
From Address must have appropriate existing access.`),
Example: fmt.Sprintf(`$ %s tx marker revoke pb1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj coindenom --from mykey`, version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
targetAddr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return cerrs.Wrapf(err, "revoke grant for invalid address %s", args[0])
}
callerAddr := clientCtx.GetFromAddress()
msg := types.NewDeleteAccessRequest(args[1], callerAddr, targetAddr)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdWithdrawCoins implements the withdraw coins from escrow command.
func GetCmdWithdrawCoins() *cobra.Command {
cmd := &cobra.Command{
Use: "withdraw [marker-denom] [coins] [(optional) recipient address]",
Aliases: []string{"w"},
Args: cobra.RangeArgs(2, 3),
Short: "Withdraw coins from the marker.",
Long: "Withdraw coins from the marker escrow account. Must be called by a user with the appropriate permissions. " +
"If the recipient is not provided then the withdrawn amount is deposited in the caller's account.",
Example: fmt.Sprintf(`$ %s tx marker withdraw coindenom 100coindenom pb1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj --from mykey`, version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
denom := args[0]
coins, err := sdk.ParseCoinsNormalized(args[1])
if err != nil {
return sdkErrors.ErrInvalidCoins.Wrapf("invalid coin %s", args[0])
}
callerAddr := clientCtx.GetFromAddress()
recipientAddr := sdk.AccAddress{}
if len(args) == 3 {
recipientAddr, err = sdk.AccAddressFromBech32(args[2])
if err != nil {
return cerrs.Wrapf(err, "invalid recipient address %s", args[2])
}
}
msg := types.NewMsgWithdrawRequest(callerAddr, recipientAddr, denom, coins)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetNewTransferCmd implements the transfer command for marker funds.
func GetNewTransferCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "transfer [from] [to] [coins]",
Aliases: []string{"t"},
Short: "Transfer coins from one account to another",
Example: fmt.Sprintf(`$ %s tx marker transfer tp1jypkeck8vywptdltjnwspwzulkqu7jv6ey90dx tp1z6403t8z42fpl760zguuf2pc24g5gq96sez0k4 100coindenom --from mykey`, version.AppName),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
from, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return cerrs.Wrapf(err, "invalid from address %s", args[0])
}
to, err := sdk.AccAddressFromBech32(args[1])
if err != nil {
return cerrs.Wrapf(err, "invalid recipient address %s", args[1])
}
coins, err := sdk.ParseCoinsNormalized(args[2])
if err != nil {
return sdkErrors.ErrInvalidCoins.Wrapf("invalid coin %s", args[2])
}
if len(coins) != 1 {
return sdkErrors.ErrInvalidCoins.Wrapf("invalid coin %s", args[2])
}
msg := types.NewMsgTransferRequest(clientCtx.GetFromAddress(), from, to, coins[0])
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetIbcTransferTxCmd returns the command to create a GetIbcTransferTxCmd transaction
func GetIbcTransferTxCmd() *cobra.Command {
// TODO: refactor ibc-transfer usage comments to be provenance specific
cmd := &cobra.Command{
Use: "ibc-transfer [src-port] [src-channel] [sender] [receiver] [amount]",
Short: "Transfer a restricted marker token through IBC",
Long: strings.TrimSpace(`Transfer a restricted marker through IBC. Timeouts can be specified
as absolute or relative using the "absolute-timeouts" flag. Timeout height can be set by passing in the height string
in the form {revision}-{height} using the "packet-timeout-height" flag. Relative timeout height is added to the block
height queried from the latest consensus state corresponding to the counterparty channel. Relative timeout timestamp
is added to the greater value of the local clock time and the block timestamp queried from the latest consensus state
corresponding to the counterparty channel. Any timeout set to 0 is disabled.`),
Example: fmt.Sprintf("%s tx marker ibc-transfer [src-port] [src-channel] [receiver] [amount]", version.AppName),
Args: cobra.ExactArgs(5),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
sourcePort := args[0]
sourceChannel := args[1]
sender := args[2]
receiver := args[3]
token, err := sdk.ParseCoinNormalized(args[4])
if err != nil {
return err
}
timeoutHeightStr, err := cmd.Flags().GetString(FlagPacketTimeoutHeight)
if err != nil {
return err
}
timeoutHeight, err := clienttypes.ParseHeight(timeoutHeightStr)
if err != nil {
return err
}
timeoutTimestamp, err := cmd.Flags().GetUint64(FlagPacketTimeoutTimestamp)
if err != nil {
return err
}
absoluteTimeouts, err := cmd.Flags().GetBool(FlagAbsoluteTimeouts)
if err != nil {
return err
}
memo, err := cmd.Flags().GetString(FlagMemo)
if err != nil {
return err
}
// if the timeouts are not absolute, retrieve latest block height and block timestamp
// for the consensus state connected to the destination port/channel
if !absoluteTimeouts {
consensusState, height, _, err := channelutils.QueryLatestConsensusState(clientCtx, sourcePort, sourceChannel)
if err != nil {
return err
}
if !timeoutHeight.IsZero() {
absoluteHeight := height
absoluteHeight.RevisionNumber += timeoutHeight.RevisionNumber
absoluteHeight.RevisionHeight += timeoutHeight.RevisionHeight
timeoutHeight = absoluteHeight
}
if timeoutTimestamp != 0 {
// use local clock time as reference time if it is later than the
// consensus state timestamp of the counter party chain, otherwise
// still use consensus state timestamp as reference
now := time.Now().UnixNano()
consensusStateTimestamp := consensusState.GetTimestamp()
if now > 0 {
now := uint64(now)
if now > consensusStateTimestamp {
timeoutTimestamp = now + timeoutTimestamp
} else {
timeoutTimestamp = consensusStateTimestamp + timeoutTimestamp
}
} else {
return errors.New("local clock time is not greater than Jan 1st, 1970 12:00 AM")
}
}
}
msg := types.NewIbcMsgTransferRequest(
clientCtx.GetFromAddress().String(),
sourcePort, sourceChannel,
token, sender, receiver,
timeoutHeight, timeoutTimestamp,
memo,
)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().String(FlagPacketTimeoutHeight, "0-1000", "Packet timeout block height. The timeout is disabled when set to 0-0.")
cmd.Flags().Uint64(FlagPacketTimeoutTimestamp, uint64((time.Duration(10) * time.Minute).Nanoseconds()), "Packet timeout timestamp in nanoseconds from now. Default is 10 minutes. The timeout is disabled when set to 0.")
cmd.Flags().Bool(FlagAbsoluteTimeouts, false, "Timeout flags are used as absolute timeouts.")
cmd.Flags().String(FlagMemo, "", "Memo to be sent along with the packet.")
flags.AddTxFlagsToCmd(cmd)
return cmd
}
func GetCmdGrantAuthorization() *cobra.Command {
cmd := &cobra.Command{
Use: "grant-authz [grantee] [authorization_type]",
Aliases: []string{"ga"},
Args: cobra.ExactArgs(2),
Short: "Grant authorization to an address",
Long: strings.TrimSpace(`grant authorization to an address to execute an authorization type [transfer]`),
Example: fmt.Sprintf(`$ %s tx marker grant-authz tp1skjw.. transfer --transfer-limit=1000nhash`, version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
grantee, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}
expSec, err := cmd.Flags().GetInt64(FlagExpiration)
if err != nil {
return err
}
var authorization authz.Authorization
switch args[1] {
case "transfer":
limit, terr := cmd.Flags().GetString(FlagTransferLimit)
if terr != nil {
return terr
}
spendLimit, terr := sdk.ParseCoinsNormalized(limit)
if terr != nil {
return terr
}
if !spendLimit.IsAllPositive() {
return fmt.Errorf("transfer-limit should be greater than zero")
}
allowList, terr := cmd.Flags().GetStringSlice(FlagAllowList)
if terr != nil {
return terr
}
allowed, terr := bech32toAccAddresses(allowList)
if terr != nil {
return terr
}
authorization = types.NewMarkerTransferAuthorization(spendLimit, allowed)
default:
return fmt.Errorf("invalid authorization type, %s", args[1])
}
exp := time.Unix(expSec, 0)
msg, err := authz.NewMsgGrant(clientCtx.GetFromAddress(), grantee, authorization, &exp)
if err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
cmd.Flags().String(FlagTransferLimit, "", "The total amount an account is allowed to transfer on granter's behalf")
cmd.Flags().StringSlice(FlagAllowList, []string{}, "Allowed addresses grantee is allowed to send restricted coins separated by ,")
cmd.Flags().Int64(FlagExpiration, time.Now().AddDate(1, 0, 0).Unix(), "The Unix timestamp. Default is one year.")
return cmd
}
// bech32toAccAddresses returns []AccAddress from a list of Bech32 string addresses.
func bech32toAccAddresses(accAddrs []string) ([]sdk.AccAddress, error) {
addrs := make([]sdk.AccAddress, len(accAddrs))
for i, addr := range accAddrs {
accAddr, err := sdk.AccAddressFromBech32(addr)
if err != nil {
return nil, err
}
addrs[i] = accAddr
}
return addrs, nil
}
func GetCmdRevokeAuthorization() *cobra.Command {
cmd := &cobra.Command{
Use: "revoke-authz [grantee] [authorization_type]",
Short: "Revoke authorization to an address",
Aliases: []string{"ra"},
Args: cobra.ExactArgs(2),
Long: strings.TrimSpace(`revoke authorization to a grantee address for authorization type [transfer]`),
Example: fmt.Sprintf(`$ %s tx marker revoke-authz tp1skjw.. transfer`, version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
grantee, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}
var action string
switch args[1] {
case "transfer":
action = types.MarkerTransferAuthorization{}.MsgTypeURL()
default:
return fmt.Errorf("invalid action type, %s", args[1])
}
msg := authz.NewMsgRevoke(clientCtx.GetFromAddress(), grantee, action)
if err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdFeeGrant returns a CLI command handler for creating a MsgGrantAllowance transaction.
func GetCmdFeeGrant() *cobra.Command {
cmd := &cobra.Command{
Use: "feegrant [denom] [administrator_key_or_address] [grantee]",
Short: "Grant Fee allowance to an address",
Long: strings.TrimSpace(
fmt.Sprintf(
`Grant authorization to pay fees from your address. Note, the'--from' flag is
ignored as it is implied from [administrator].
Examples:
%s tx %s feegrant markerdenom pb1edlyu... pb1psh7r... --spend-limit 100stake --expiration 2022-01-30T15:04:05Z or
%s tx %s feegrant markerdenom pb1edlyu... pb1psh7r... --spend-limit 100stake --period 3600 --period-limit 10stake --expiration 36000 or
%s tx %s feegrant markerdenom pb1edlyu... pb1psh7r... --spend-limit 100stake --expiration 2022-01-30T15:04:05Z
--allowed-messages "/cosmos.gov.v1beta1.MsgSubmitProposal,/cosmos.gov.v1beta1.MsgVote"
`, version.AppName, types.ModuleName, version.AppName, types.ModuleName, version.AppName, types.ModuleName,
),
),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
denom := args[0]
err := cmd.Flags().Set(flags.FlagFrom, args[1])
if err != nil {
return err
}
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
grantee, err := sdk.AccAddressFromBech32(args[2])
if err != nil {
return err
}
administrator := clientCtx.GetFromAddress()
sl, err := cmd.Flags().GetString(FlagSpendLimit)
if err != nil {
return err
}
// if `FlagSpendLimit` isn't set, limit will be nil
limit, err := sdk.ParseCoinsNormalized(sl)
if err != nil {
return err
}
exp, err := cmd.Flags().GetString(FlagExpiration)
if err != nil {
return err
}
basic := feegrant.BasicAllowance{
SpendLimit: limit,
}
var expiresAtTime time.Time
if exp != "" {
expiresAtTime, err = time.Parse(time.RFC3339, exp)
if err != nil {
return err
}
basic.Expiration = &expiresAtTime
}
var allowance feegrant.FeeAllowanceI
allowance = &basic
periodClock, err := cmd.Flags().GetInt64(FlagPeriod)
if err != nil {
return err
}
periodLimitVal, err := cmd.Flags().GetString(FlagPeriodLimit)
if err != nil {
return err
}
// Check any of period or periodLimit flags set, If set consider it as periodic fee allowance.
if periodClock > 0 || periodLimitVal != "" {
var periodLimit sdk.Coins
periodLimit, err = sdk.ParseCoinsNormalized(periodLimitVal)
if err != nil {
return err
}
if periodClock <= 0 {
return fmt.Errorf("period clock was not set")
}
if periodLimit == nil {
return fmt.Errorf("period limit was not set")
}
periodReset := getPeriodReset(periodClock)
if exp != "" && periodReset.Sub(expiresAtTime) > 0 {
return fmt.Errorf("period (%d) cannot reset after expiration (%v)", periodClock, exp)
}
periodic := feegrant.PeriodicAllowance{
Basic: basic,
Period: getPeriod(periodClock),
PeriodReset: getPeriodReset(periodClock),
PeriodSpendLimit: periodLimit,
PeriodCanSpend: periodLimit,
}
allowance = &periodic
}
allowedMsgs, err := cmd.Flags().GetStringSlice(FlagAllowedMsgs)
if err != nil {
return err
}
if len(allowedMsgs) > 0 {
allowance, err = feegrant.NewAllowedMsgAllowance(allowance, allowedMsgs)
if err != nil {
return err
}
}
msg, err := types.NewMsgGrantAllowance(denom, administrator, grantee, allowance)
if err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
cmd.Flags().StringSlice(FlagAllowedMsgs, []string{}, "Set of allowed messages for fee allowance")
cmd.Flags().String(FlagExpiration, "", "The RFC 3339 timestamp after which the grant expires for the user")
cmd.Flags().String(FlagSpendLimit, "", "Spend limit specifies the max limit can be used, if not mentioned there is no limit")
cmd.Flags().Int64(FlagPeriod, 0, "period specifies the time duration in which period_spend_limit coins can be spent before that allowance is reset")
cmd.Flags().String(FlagPeriodLimit, "", "period limit specifies the maximum number of coins that can be spent in the period")
return cmd
}
// GetCmdAddFinalizeActivateMarker implements the add finalize activate marker command
func GetCmdAddFinalizeActivateMarker() *cobra.Command {
cmd := &cobra.Command{
Use: "create-finalize-activate [coin] [access-grant-string]",
Aliases: []string{"cfa"},
Args: cobra.ExactArgs(2),
Short: "Creates, Finalizes and Activates a new marker",
Long: strings.TrimSpace(`Creates a new marker, finalizes it and put's it ACTIVATED state managed by the from address
with the given supply amount and denomination provided in the coin argument
`),
Example: fmt.Sprintf(`$ %s tx marker create-finalize-activate 1000hotdogcoin address1,mint,admin;address2,burn --%s=false --%s=false --%s=attr.one,*.attr.two,... --from=mykey`,
FlagType,
FlagSupplyFixed,
FlagAllowGovernanceControl,
FlagRequiredAttributes,
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
coin, err := sdk.ParseCoinNormalized(args[0])
if err != nil {
return fmt.Errorf("invalid coin %s", args[0])
}
callerAddr := clientCtx.GetFromAddress()
flagVals, err := ParseNewMarkerFlags(cmd)
if err != nil {
return err
}
accessGrants := ParseAccessGrantFromString(args[1])
if len(accessGrants) == 0 {
panic("at least one access grant should be present.")
}
msg := types.NewMsgAddFinalizeActivateMarkerRequest(
coin.Denom, coin.Amount, callerAddr, callerAddr, flagVals.MarkerType,
flagVals.SupplyFixed, flagVals.AllowGovControl,
flagVals.AllowForceTransfer, flagVals.RequiredAttributes, accessGrants, flagVals.UsdMills, flagVals.Volume,
)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
AddNewMarkerFlags(cmd)
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdUpdateRequiredAttributes implements the update required attributes command
func GetCmdUpdateRequiredAttributes() *cobra.Command {
cmd := &cobra.Command{
Use: "update-required-attributes <denom>",
Aliases: []string{"ura"},
Args: cobra.ExactArgs(1),
Short: "Update required attributes on an existing restricted marker",
Long: strings.TrimSpace(`Updates the required attributes of an existing restricted marker.
`),
Example: fmt.Sprintf(`$ %s tx marker update-required-attributes hotdogcoin --%s=attr.one,*.attr.two,... --%s=attr.one,*.attr.two,...`,
version.AppName,
FlagAdd,
FlagRemove,
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
flagSet := cmd.Flags()
msg := &types.MsgUpdateRequiredAttributesRequest{Denom: args[0]}
msg.AddRequiredAttributes, err = flagSet.GetStringSlice(FlagAdd)
if err != nil {
return fmt.Errorf("incorrect value for %s flag. Accepted: comma delimited list of attributes Error: %w", FlagAdd, err)
}
msg.RemoveRequiredAttributes, err = flagSet.GetStringSlice(FlagRemove)
if err != nil {
return fmt.Errorf("incorrect value for %s flag. Accepted: comma delimited list of attributes Error: %w", FlagRemove, err)
}
authSetter := func(authority string) {
msg.TransferAuthority = authority
}
return generateOrBroadcastOptGovProp(clientCtx, flagSet, authSetter, msg)
},
}
cmd.Flags().StringSlice(FlagAdd, []string{}, "comma delimited list of required attributes to be added to restricted marker")
cmd.Flags().StringSlice(FlagRemove, []string{}, "comma delimited list of required attributes to be removed from restricted marker")
addOptGovPropFlags(cmd)
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdUpdateForcedTransfer returns a CLI command for updating a marker's allow_force_transfer flag.
func GetCmdUpdateForcedTransfer() *cobra.Command {
cmd := &cobra.Command{
Use: "update-forced-transfer <denom> {true|false}",
Aliases: []string{"uft"},
Short: "Submit a governance proposal to update the allow_forced_transfer field on a restricted marker",
Example: fmt.Sprintf("$ %s tx marker update-forced-transfer hotdogcoin true", version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewMsgUpdateForcedTransferRequest(args[0], false, authtypes.NewModuleAddress(govtypes.ModuleName))
msg.AllowForcedTransfer, err = ParseBoolStrict(args[1])
if err != nil {
return err
}
err = msg.ValidateBasic()
if err != nil {
return err
}
return govcli.GenerateOrBroadcastTxCLIAsGovProp(clientCtx, cmd.Flags(), msg)
},
}
govcli.AddGovPropFlagsToCmd(cmd)
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdUpdateSendDenyListRequest implements the update deny list command
func GetCmdUpdateSendDenyListRequest() *cobra.Command {
cmd := &cobra.Command{
Use: "update-deny-list <denom>",
Aliases: []string{"udl", "deny-list", "deny"},
Args: cobra.ExactArgs(1),
Short: "Update list of addresses for a restricted marker that are allowed to execute transfers",
Long: strings.TrimSpace(`Update list of addresses for a restricted marker that are allowed to execute transfers.
`),
Example: fmt.Sprintf(`$ %s tx marker update-deny-list hotdogcoin --%s=bech32addr1,bech32addrs2,... --%s=bech32addr1,bech32addrs2,...`,
version.AppName,
FlagAdd,
FlagRemove,
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
flagSet := cmd.Flags()
msg := &types.MsgUpdateSendDenyListRequest{Denom: args[0]}
msg.AddDeniedAddresses, err = flagSet.GetStringSlice(FlagAdd)
if err != nil {
return fmt.Errorf("incorrect value for %s flag. Accepted: comma delimited list of bech32 addresses Error: %w", FlagAdd, err)
}
msg.RemoveDeniedAddresses, err = flagSet.GetStringSlice(FlagRemove)
if err != nil {
return fmt.Errorf("incorrect value for %s flag. Accepted: comma delimited list of bech32 addresses Error: %w", FlagRemove, err)
}
authSetter := func(authority string) {
msg.Authority = authority
}