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"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
2021-06-02 17:03:25 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
|
|
|
govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
|
|
|
|
|
|
|
|
"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
|
|
|
|
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
|
|
|
|
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.
|
|
|
|
func ProposalRESTHandler(cliCtx context.CLIContext) govrest.ProposalRESTHandler {
|
|
|
|
return govrest.ProposalRESTHandler{
|
|
|
|
SubRoute: types.ProposalTypeCommunityPoolMultiSpend,
|
|
|
|
Handler: postProposalHandlerFn(cliCtx),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func postProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var req CommunityPoolMultiSpendProposalReq
|
|
|
|
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.BaseReq = req.BaseReq.Sanitize()
|
|
|
|
if !req.BaseReq.ValidateBasic(w) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
content := types.NewCommunityPoolMultiSpendProposal(req.Title, req.Description, req.RecipientList)
|
|
|
|
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})
|
|
|
|
}
|
|
|
|
}
|