-
Notifications
You must be signed in to change notification settings - Fork 1
/
rest.go
46 lines (38 loc) · 1.47 KB
/
rest.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
package rest
import (
"net/http"
"github.com/FiboChain/fbc/libs/cosmos-sdk/client/context"
sdk "github.com/FiboChain/fbc/libs/cosmos-sdk/types"
"github.com/FiboChain/fbc/libs/cosmos-sdk/types/rest"
"github.com/FiboChain/fbc/libs/cosmos-sdk/x/auth/client/utils"
"github.com/FiboChain/fbc/libs/cosmos-sdk/x/params"
"github.com/FiboChain/fbc/x/gov"
govrest "github.com/FiboChain/fbc/x/gov/client/rest"
paramscutils "github.com/FiboChain/fbc/x/params/client/utils"
)
// ProposalRESTHandler returns a ProposalRESTHandler that exposes the param change REST handler with a given sub-route
func ProposalRESTHandler(cliCtx context.CLIContext) govrest.ProposalRESTHandler {
return govrest.ProposalRESTHandler{
SubRoute: "param_change",
Handler: postProposalHandlerFn(cliCtx),
}
}
func postProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req paramscutils.ParamChangeProposalReq
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
req.BaseReq = req.BaseReq.Sanitize()
if !req.BaseReq.ValidateBasic(w) {
return
}
content := params.NewParameterChangeProposal(req.Title, req.Description, req.Changes.ToParamChanges())
msg := gov.NewMsgSubmitProposal(content, req.Deposit, req.Proposer)
if err := msg.ValidateBasic(); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}