-
Notifications
You must be signed in to change notification settings - Fork 93
/
gov_tx.go
204 lines (171 loc) · 5.97 KB
/
gov_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
package cli
import (
"strconv"
"strings"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/public-awesome/stargaze/v11/x/globalfee/types"
"github.com/spf13/cobra"
)
func CmdProposalSetCodeAuthorization() *cobra.Command {
cmd := &cobra.Command{
Use: "set-code-authorization-proposal [code-id] [methods]",
Short: "Creates a proposal which creates or updates the gasless operation authorization for the given code id and for the provided methods",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, proposalTitle, proposalDescr, deposit, err := getProposalInfo(cmd)
if err != nil {
return err
}
codeID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}
methods := strings.Split(args[1], ",")
prop := types.SetCodeAuthorizationProposal{
Title: proposalTitle,
Description: proposalDescr,
CodeAuthorization: &types.CodeAuthorization{
CodeID: codeID,
Methods: methods,
},
}
msg, err := govtypes.NewMsgSubmitProposal(&prop, deposit, clientCtx.GetFromAddress())
if err != nil {
return err
}
if err = msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().String(cli.FlagTitle, "", "Title of proposal")
cmd.Flags().String(cli.FlagDescription, "", "Description of proposal")
cmd.Flags().String(cli.FlagDeposit, "", "Deposit of proposal")
return cmd
}
func CmdProposalRemoveCodeAuthorization() *cobra.Command {
cmd := &cobra.Command{
Use: "remove-code-authorization-proposal [code-id]",
Short: "Creates a proposal which removes any previously set code authorizations",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, proposalTitle, proposalDescr, deposit, err := getProposalInfo(cmd)
if err != nil {
return err
}
codeID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}
content := types.RemoveCodeAuthorizationProposal{
Title: proposalTitle,
Description: proposalDescr,
CodeID: codeID,
}
msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress())
if err != nil {
return err
}
if err = msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().String(cli.FlagTitle, "", "Title of proposal")
cmd.Flags().String(cli.FlagDescription, "", "Description of proposal")
cmd.Flags().String(cli.FlagDeposit, "", "Deposit of proposal")
return cmd
}
func CmdProposalSetContractAuthorization() *cobra.Command {
cmd := &cobra.Command{
Use: "set-contract-authorization-proposal [contract-address] [methods]",
Short: "Creates a proposal which creates or updates the gasless operation authorization for the given contract address and for the provided methods",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, proposalTitle, proposalDescr, deposit, err := getProposalInfo(cmd)
if err != nil {
return err
}
methods := strings.Split(args[1], ",")
content := types.SetContractAuthorizationProposal{
Title: proposalTitle,
Description: proposalDescr,
ContractAuthorization: &types.ContractAuthorization{
ContractAddress: args[0],
Methods: methods,
},
}
msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress())
if err != nil {
return err
}
if err = msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().String(cli.FlagTitle, "", "Title of proposal")
cmd.Flags().String(cli.FlagDescription, "", "Description of proposal")
cmd.Flags().String(cli.FlagDeposit, "", "Deposit of proposal")
return cmd
}
func CmdProposalRemoveContractAuthorization() *cobra.Command {
cmd := &cobra.Command{
Use: "remove-contract-authorization-proposal [contract-address]",
Short: "Creates a proposal which removes any previously set contract authorizations",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, proposalTitle, proposalDescr, deposit, err := getProposalInfo(cmd)
if err != nil {
return err
}
content := types.RemoveContractAuthorizationProposal{
Title: proposalTitle,
Description: proposalDescr,
ContractAddress: args[0],
}
msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress())
if err != nil {
return err
}
if err = msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().String(cli.FlagTitle, "", "Title of proposal")
cmd.Flags().String(cli.FlagDescription, "", "Description of proposal")
cmd.Flags().String(cli.FlagDeposit, "", "Deposit of proposal")
return cmd
}
func getProposalInfo(cmd *cobra.Command) (client.Context, string, string, sdk.Coins, error) {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return client.Context{}, "", "", nil, err
}
proposalTitle, err := cmd.Flags().GetString(cli.FlagTitle)
if err != nil {
return clientCtx, proposalTitle, "", nil, err
}
proposalDescr, err := cmd.Flags().GetString(cli.FlagDescription)
if err != nil {
return client.Context{}, proposalTitle, proposalDescr, nil, err
}
depositArg, err := cmd.Flags().GetString(cli.FlagDeposit)
if err != nil {
return client.Context{}, proposalTitle, proposalDescr, nil, err
}
deposit, err := sdk.ParseCoinsNormalized(depositArg)
if err != nil {
return client.Context{}, proposalTitle, proposalDescr, deposit, err
}
return clientCtx, proposalTitle, proposalDescr, deposit, nil
}