-
Notifications
You must be signed in to change notification settings - Fork 117
/
tx.go
194 lines (158 loc) · 5.39 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
package cli
import (
"fmt"
"time"
"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"
"github.com/spf13/cobra"
"github.com/axelarnetwork/axelar-core/x/nexus/exported"
"github.com/axelarnetwork/axelar-core/x/nexus/types"
)
// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
txCmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
TraverseChildren: true,
RunE: client.ValidateCmd,
}
txCmd.AddCommand(
GetCmdRegisterChainMaintainer(),
GetCmdDeregisterChainMaintainer(),
GetCmdActivateChain(),
GetCmdDeactivateChain(),
GetCmdRegisterAssetFee(),
GetCmdSetTransferRateLimit(),
)
return txCmd
}
// GetCmdRegisterChainMaintainer returns the cli command to register a validator as a chain maintainer for the given chains
func GetCmdRegisterChainMaintainer() *cobra.Command {
cmd := &cobra.Command{
Use: "register-chain-maintainer [chain]...",
Short: "register a validator as a chain maintainer for the given chains",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewRegisterChainMaintainerRequest(cliCtx.GetFromAddress(), args...)
return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdDeregisterChainMaintainer returns the cli command to deregister a validator as a chain maintainer for the given chains
func GetCmdDeregisterChainMaintainer() *cobra.Command {
cmd := &cobra.Command{
Use: "deregister-chain-maintainer [chain]...",
Short: "deregister a validator as a chain maintainer for the given chains",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewDeregisterChainMaintainerRequest(cliCtx.GetFromAddress(), args...)
return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdActivateChain returns the cli command to activate the given chains
func GetCmdActivateChain() *cobra.Command {
cmd := &cobra.Command{
Use: "activate-chain [chain]...",
Short: "activate the given chains",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewActivateChainRequest(cliCtx.GetFromAddress(), args...)
return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdDeactivateChain returns the cli command to deactivate the given chains
func GetCmdDeactivateChain() *cobra.Command {
cmd := &cobra.Command{
Use: "deactivate-chain [chain]...",
Short: "deactivate the given chains",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewDeactivateChainRequest(cliCtx.GetFromAddress(), args...)
return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdRegisterAssetFee returns the cli command to register an asset fee
func GetCmdRegisterAssetFee() *cobra.Command {
cmd := &cobra.Command{
Use: "register-asset-fee [chain] [asset] [fee-rate] [min-fee] [max-fee]",
Short: "register fees for an asset on a chain",
Args: cobra.ExactArgs(5),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
feeRate := sdk.MustNewDecFromStr(args[2])
minFee, ok := sdk.NewIntFromString(args[3])
if !ok {
return fmt.Errorf("invalid value provided for min fee")
}
maxFee, ok := sdk.NewIntFromString(args[4])
if !ok {
return fmt.Errorf("invalid value provided for max fee")
}
feeInfo := exported.NewFeeInfo(exported.ChainName(args[0]), args[1], feeRate, minFee, maxFee)
msg := types.NewRegisterAssetFeeRequest(cliCtx.GetFromAddress(), feeInfo)
return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdSetTransferRateLimit returns the cli command to register asset transfer rate limit for a chain
func GetCmdSetTransferRateLimit() *cobra.Command {
cmd := &cobra.Command{
Use: "set-transfer-rate-limit [chain] [limit] [window]",
Short: "set transfer rate limit for an asset on a chain",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
limit, err := sdk.ParseCoinNormalized(args[1])
if err != nil {
return err
}
window, err := time.ParseDuration(args[2])
if err != nil {
return err
}
msg := types.NewSetTransferRateLimitRequest(cliCtx.GetFromAddress(), exported.ChainName(args[0]), limit, window)
return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}