2019-02-04 16:45:18 -08:00
|
|
|
package rest
|
|
|
|
|
|
|
|
import (
|
2019-05-21 03:02:10 -07:00
|
|
|
"net/http"
|
2019-02-08 13:45:41 -08:00
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/gorilla/mux"
|
|
|
|
|
2019-02-04 16:45:18 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
2019-05-21 03:02:10 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
2020-01-24 08:40:56 -08:00
|
|
|
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
2019-05-21 03:02:10 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
|
|
|
govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
|
2019-02-04 16:45:18 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
// RegisterRoutes register distribution REST routes.
|
2019-06-06 08:43:15 -07:00
|
|
|
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, queryRoute string) {
|
|
|
|
registerQueryRoutes(cliCtx, r, queryRoute)
|
|
|
|
registerTxRoutes(cliCtx, r, queryRoute)
|
2019-02-04 16:45:18 -08:00
|
|
|
}
|
2019-05-21 03:02:10 -07:00
|
|
|
|
|
|
|
// ProposalRESTHandler returns a ProposalRESTHandler that exposes the community pool spend REST handler with a given sub-route.
|
2019-06-06 08:43:15 -07:00
|
|
|
func ProposalRESTHandler(cliCtx context.CLIContext) govrest.ProposalRESTHandler {
|
2019-05-21 03:02:10 -07:00
|
|
|
return govrest.ProposalRESTHandler{
|
|
|
|
SubRoute: "community_pool_spend",
|
2019-06-06 08:43:15 -07:00
|
|
|
Handler: postProposalHandlerFn(cliCtx),
|
2019-05-21 03:02:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 08:43:15 -07:00
|
|
|
func postProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
2019-05-21 03:02:10 -07:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var req CommunityPoolSpendProposalReq
|
2019-06-06 08:43:15 -07:00
|
|
|
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
|
2019-05-21 03:02:10 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
req.BaseReq = req.BaseReq.Sanitize()
|
|
|
|
if !req.BaseReq.ValidateBasic(w) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
content := types.NewCommunityPoolSpendProposal(req.Title, req.Description, req.Recipient, req.Amount)
|
2019-05-21 03:02:10 -07:00
|
|
|
|
|
|
|
msg := gov.NewMsgSubmitProposal(content, req.Deposit, req.Proposer)
|
|
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
|
|
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-24 08:40:56 -08:00
|
|
|
authclient.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
|
2019-05-21 03:02:10 -07:00
|
|
|
}
|
|
|
|
}
|