2020-06-12 19:45:07 +00:00
|
|
|
package rest
|
|
|
|
|
|
|
|
import (
|
2021-06-02 17:03:25 +00:00
|
|
|
"net/http"
|
|
|
|
|
2020-06-12 19:45:07 +00:00
|
|
|
"github.com/gorilla/mux"
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
|
|
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/tx"
|
2021-06-02 17:03:25 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
|
|
|
govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
|
2022-01-08 00:39:27 +00:00
|
|
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
2021-06-02 17:03:25 +00:00
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/kavadist/types"
|
2020-06-12 19:45:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// RegisterRoutes registers kavadist-related REST handlers to a router
|
2022-01-08 00:39:27 +00:00
|
|
|
func RegisterRoutes(cliCtx client.Context, rtr *mux.Router) {
|
|
|
|
r := clientrest.WithHTTPDeprecationHeaders(rtr)
|
2020-06-12 19:45:07 +00:00
|
|
|
registerQueryRoutes(cliCtx, r)
|
|
|
|
}
|
2021-06-02 17:03:25 +00:00
|
|
|
|
|
|
|
// ProposalRESTHandler returns a ProposalRESTHandler that exposes the community pool multi-spend REST handler with a given sub-route.
|
2022-01-08 00:39:27 +00:00
|
|
|
func ProposalRESTHandler(cliCtx client.Context) govrest.ProposalRESTHandler {
|
2021-06-02 17:03:25 +00:00
|
|
|
return govrest.ProposalRESTHandler{
|
|
|
|
SubRoute: types.ProposalTypeCommunityPoolMultiSpend,
|
|
|
|
Handler: postProposalHandlerFn(cliCtx),
|
|
|
|
}
|
|
|
|
}
|
2022-05-09 18:37:36 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func postProposalHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
2021-06-02 17:03:25 +00:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var req CommunityPoolMultiSpendProposalReq
|
2022-01-08 00:39:27 +00:00
|
|
|
if !rest.ReadRESTReq(w, r, cliCtx.LegacyAmino, &req) {
|
2021-06-02 17:03:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
req.BaseReq = req.BaseReq.Sanitize()
|
|
|
|
if !req.BaseReq.ValidateBasic(w) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
content := types.NewCommunityPoolMultiSpendProposal(req.Title, req.Description, req.RecipientList)
|
2022-01-08 00:39:27 +00:00
|
|
|
msg, err := govtypes.NewMsgSubmitProposal(content, req.Deposit, req.Proposer)
|
|
|
|
if rest.CheckBadRequestError(w, err) {
|
2021-06-02 17:03:25 +00:00
|
|
|
return
|
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
if rest.CheckBadRequestError(w, msg.ValidateBasic()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, msg)
|
2021-06-02 17:03:25 +00:00
|
|
|
}
|
|
|
|
}
|