Skip to content

Commit 0aae6f1

Browse files
committed
add stop consumer chain gov proposal handler
1 parent 4a146b2 commit 0aae6f1

File tree

2 files changed

+108
-5
lines changed

2 files changed

+108
-5
lines changed

app/provider/app.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ var (
142142
upgradeclient.CancelProposalHandler,
143143
ibcclientclient.UpdateClientProposalHandler,
144144
ibcclientclient.UpgradeProposalHandler,
145-
ibcproviderclient.ProposalHandler,
145+
ibcproviderclient.CreateConsumerProposalHandler,
146+
ibcproviderclient.StopConsumerProposalHandler,
146147
),
147148
params.AppModuleBasic{},
148149
crisis.AppModuleBasic{},

x/ccv/provider/client/proposal_handler.go

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import (
2121
)
2222

2323
// 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+
)
2528

2629
// NewCreateConsumerChainProposalTxCmd returns a CLI command handler for creating
2730
// a new consumer chain proposal governance transaction.
@@ -85,6 +88,64 @@ Where proposal.json contains:
8588
}
8689
}
8790

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+
88149
type CreateConsumerChainProposalJSON struct {
89150
Title string `json:"title"`
90151
Description string `json:"description"`
@@ -162,15 +223,16 @@ func ParseStopConsumerChainProposalJSON(proposalFile string) (StopConsumerChainP
162223

163224
// CreateConsumerProposalRESTHandler returns a ProposalRESTHandler that exposes the param
164225
// change REST handler with a given sub-route.
165-
func ProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler {
226+
func CreateConsumerProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler {
166227
return govrest.ProposalRESTHandler{
167228
SubRoute: "create_consumer_chain",
168-
Handler: postProposalHandlerFn(clientCtx),
229+
Handler: postCreateConsumerProposalHandlerFn(clientCtx),
169230
}
170231
}
171232

172-
func postProposalHandlerFn(clientCtx client.Context) http.HandlerFunc {
233+
func postCreateConsumerProposalHandlerFn(clientCtx client.Context) http.HandlerFunc {
173234
return func(w http.ResponseWriter, r *http.Request) {
235+
// var req CreateConsumerChainProposalReq
174236
var req CreateConsumerChainProposalReq
175237
if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) {
176238
return
@@ -197,3 +259,43 @@ func postProposalHandlerFn(clientCtx client.Context) http.HandlerFunc {
197259
tx.WriteGeneratedTxResponse(clientCtx, w, req.BaseReq, msg)
198260
}
199261
}
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

Comments
 (0)