@@ -21,7 +21,10 @@ import (
21
21
)
22
22
23
23
// ProposalHandler is the param change proposal handler.
24
- var ProposalHandler = govclient .NewProposalHandler (NewCreateConsumerChainProposalTxCmd , ProposalRESTHandler )
24
+ var (
25
+ CreateConsumerProposalHandler = govclient .NewProposalHandler (NewCreateConsumerChainProposalTxCmd , CreateConsumerProposalRESTHandler )
26
+ StopConsumerProposalHandler = govclient .NewProposalHandler (NewStopConsumerChainProposalTxCmd , StopConsumerProposalRESTHandler )
27
+ )
25
28
26
29
// NewCreateConsumerChainProposalTxCmd returns a CLI command handler for creating
27
30
// a new consumer chain proposal governance transaction.
@@ -85,6 +88,64 @@ Where proposal.json contains:
85
88
}
86
89
}
87
90
91
+ // NewStopConsumerChainProposalTxCmd returns a CLI command handler for stopping
92
+ // a new consumer chain proposal governance transaction.
93
+ func NewStopConsumerChainProposalTxCmd () * cobra.Command {
94
+ return & cobra.Command {
95
+ Use : "stop-consumer-chain [proposal-file]" ,
96
+ Args : cobra .ExactArgs (1 ),
97
+ Short : "Submit a consumer chain stoppage proposal" ,
98
+ Long : `
99
+ Submit a consumer chain stoppage proposal along with an initial deposit.
100
+ The proposal details must be supplied via a JSON file.
101
+
102
+ Example:
103
+ $ %s tx gov submit-proposal create-consumer-chain <path/to/proposal.json> --from=<key_or_address>
104
+
105
+ Where proposal.json contains:
106
+
107
+ {
108
+ "title": "Stop the FooChain",
109
+ "description": "It was a great chain",
110
+ "chain_id": "foochain",
111
+ "stop_time": "2022-01-27T15:59:50.121607-08:00",
112
+ "deposit": "10000stake"
113
+ }
114
+ ` ,
115
+ RunE : func (cmd * cobra.Command , args []string ) error {
116
+ clientCtx , err := client .GetClientTxContext (cmd )
117
+ if err != nil {
118
+ return err
119
+ }
120
+
121
+ proposal , err := ParseStopConsumerChainProposalJSON (args [0 ])
122
+ if err != nil {
123
+ return err
124
+ }
125
+
126
+ content , err := types .NewStopConsumerChainProposal (
127
+ proposal .Title , proposal .Description , proposal .ChainId , proposal .StopTime )
128
+ if err != nil {
129
+ return err
130
+ }
131
+
132
+ from := clientCtx .GetFromAddress ()
133
+
134
+ deposit , err := sdk .ParseCoinsNormalized (proposal .Deposit )
135
+ if err != nil {
136
+ return err
137
+ }
138
+
139
+ msg , err := govtypes .NewMsgSubmitProposal (content , deposit , from )
140
+ if err != nil {
141
+ return err
142
+ }
143
+
144
+ return tx .GenerateOrBroadcastTxCLI (clientCtx , cmd .Flags (), msg )
145
+ },
146
+ }
147
+ }
148
+
88
149
type CreateConsumerChainProposalJSON struct {
89
150
Title string `json:"title"`
90
151
Description string `json:"description"`
@@ -162,15 +223,16 @@ func ParseStopConsumerChainProposalJSON(proposalFile string) (StopConsumerChainP
162
223
163
224
// CreateConsumerProposalRESTHandler returns a ProposalRESTHandler that exposes the param
164
225
// change REST handler with a given sub-route.
165
- func ProposalRESTHandler (clientCtx client.Context ) govrest.ProposalRESTHandler {
226
+ func CreateConsumerProposalRESTHandler (clientCtx client.Context ) govrest.ProposalRESTHandler {
166
227
return govrest.ProposalRESTHandler {
167
228
SubRoute : "create_consumer_chain" ,
168
- Handler : postProposalHandlerFn (clientCtx ),
229
+ Handler : postCreateConsumerProposalHandlerFn (clientCtx ),
169
230
}
170
231
}
171
232
172
- func postProposalHandlerFn (clientCtx client.Context ) http.HandlerFunc {
233
+ func postCreateConsumerProposalHandlerFn (clientCtx client.Context ) http.HandlerFunc {
173
234
return func (w http.ResponseWriter , r * http.Request ) {
235
+ // var req CreateConsumerChainProposalReq
174
236
var req CreateConsumerChainProposalReq
175
237
if ! rest .ReadRESTReq (w , r , clientCtx .LegacyAmino , & req ) {
176
238
return
@@ -197,3 +259,43 @@ func postProposalHandlerFn(clientCtx client.Context) http.HandlerFunc {
197
259
tx .WriteGeneratedTxResponse (clientCtx , w , req .BaseReq , msg )
198
260
}
199
261
}
262
+
263
+ // StopConsumerProposalRESTHandler returns a ProposalRESTHandler that exposes the param
264
+ // change REST handler with a given sub-route.
265
+ func StopConsumerProposalRESTHandler (clientCtx client.Context ) govrest.ProposalRESTHandler {
266
+ return govrest.ProposalRESTHandler {
267
+ SubRoute : "stop_consumer_chain" ,
268
+ Handler : postStopConsumerProposalHandlerFn (clientCtx ),
269
+ }
270
+ }
271
+
272
+ func postStopConsumerProposalHandlerFn (clientCtx client.Context ) http.HandlerFunc {
273
+ return func (w http.ResponseWriter , r * http.Request ) {
274
+ var req StopConsumerChainProposalReq
275
+ if ! rest .ReadRESTReq (w , r , clientCtx .LegacyAmino , & req ) {
276
+ return
277
+ }
278
+
279
+ req .BaseReq = req .BaseReq .Sanitize ()
280
+ if ! req .BaseReq .ValidateBasic (w ) {
281
+ return
282
+ }
283
+
284
+ content , err := types .NewStopConsumerChainProposal (
285
+ req .Title , req .Description , req .ChainId , req .StopTime )
286
+ if rest .CheckBadRequestError (w , err ) {
287
+ return
288
+ }
289
+
290
+ msg , err := govtypes .NewMsgSubmitProposal (content , req .Deposit , req .Proposer )
291
+ if rest .CheckBadRequestError (w , err ) {
292
+ return
293
+ }
294
+
295
+ if rest .CheckBadRequestError (w , msg .ValidateBasic ()) {
296
+ return
297
+ }
298
+
299
+ tx .WriteGeneratedTxResponse (clientCtx , w , req .BaseReq , msg )
300
+ }
301
+ }
0 commit comments