2019-11-25 19:46:02 +00:00
|
|
|
package rest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
|
|
|
|
2020-01-16 17:52:29 +00:00
|
|
|
"github.com/kava-labs/kava/x/auction/types"
|
|
|
|
)
|
2019-11-25 19:46:02 +00:00
|
|
|
|
|
|
|
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
|
|
|
|
r.HandleFunc(fmt.Sprintf("/auction/getauctions"), queryGetAuctionsHandlerFn(cliCtx)).Methods("GET")
|
2020-01-16 17:52:29 +00:00
|
|
|
r.HandleFunc("/auction/params", getParamsHandlerFn(cliCtx)).Methods("GET")
|
2019-11-25 19:46:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func queryGetAuctionsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
res, height, err := cliCtx.QueryWithData("/custom/auction/getauctions", nil)
|
|
|
|
if err != nil {
|
|
|
|
rest.WriteErrorResponse(w, http.StatusNotFound, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
cliCtx = cliCtx.WithHeight(height)
|
|
|
|
rest.PostProcessResponse(w, cliCtx, res)
|
|
|
|
}
|
|
|
|
}
|
2020-01-16 17:52:29 +00:00
|
|
|
|
|
|
|
func getParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// Get the params
|
|
|
|
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/auction/%s", types.QueryGetParams), nil)
|
|
|
|
cliCtx = cliCtx.WithHeight(height)
|
|
|
|
if err != nil {
|
|
|
|
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// Return the params
|
|
|
|
rest.PostProcessResponse(w, cliCtx, res)
|
|
|
|
}
|
|
|
|
}
|