package rest import ( "net/http" "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client/context" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/gov" govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest" ) func RegisterHandlers(cliCtx context.CLIContext, r *mux.Router) { registerQueryRoutes(cliCtx, r) registerTxHandlers(cliCtx, r) } // RegisterRoutes register distribution REST routes. func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, queryRoute string) { registerQueryRoutes(cliCtx, r) registerTxRoutes(cliCtx, r, queryRoute) } // TODO add proto compatible Handler after x/gov migration // ProposalRESTHandler returns a ProposalRESTHandler that exposes the community pool spend REST handler with a given sub-route. func ProposalRESTHandler(cliCtx context.CLIContext) govrest.ProposalRESTHandler { return govrest.ProposalRESTHandler{ SubRoute: "community_pool_spend", Handler: postProposalHandlerFn(cliCtx), } } func postProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req CommunityPoolSpendProposalReq if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { return } req.BaseReq = req.BaseReq.Sanitize() if !req.BaseReq.ValidateBasic(w) { return } content := types.NewCommunityPoolSpendProposal(req.Title, req.Description, req.Recipient, req.Amount) msg, err := gov.NewMsgSubmitProposal(content, req.Deposit, req.Proposer) if rest.CheckBadRequestError(w, err) { return } if rest.CheckBadRequestError(w, msg.ValidateBasic()) { return } authclient.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg}) } }