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" "github.com/cosmos/cosmos-sdk/x/auth/client/utils" "github.com/kava-labs/kava/x/liquidator/types" ) func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) { r.HandleFunc("/liquidator/seize", seizeCdpHandlerFn(cliCtx)).Methods("POST") r.HandleFunc("/liquidator/mint", debtAuctionHandlerFn(cliCtx)).Methods("POST") } func seizeCdpHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { // Get args from post body var req types.SeizeAndStartCollateralAuctionRequest if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { // This function writes a response on error return } req.BaseReq = req.BaseReq.Sanitize() if !req.BaseReq.ValidateBasic(w) { // This function writes a response on error return } // Create msg msg := types.MsgSeizeAndStartCollateralAuction{ req.Sender, req.CdpOwner, req.CollateralDenom, } if err := msg.ValidateBasic(); err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return } // Generate tx and write response utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg}) } } func debtAuctionHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { // Get args from post body var req types.StartDebtAuctionRequest if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { return } req.BaseReq = req.BaseReq.Sanitize() if !req.BaseReq.ValidateBasic(w) { return } // Create msg msg := types.MsgStartDebtAuction{ req.Sender, } if err := msg.ValidateBasic(); err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return } // Generate tx and write response utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg}) } }