2020-06-12 19:45:07 +00:00
|
|
|
package rest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2020-06-12 19:45:07 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/kavadist/types"
|
|
|
|
)
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func registerQueryRoutes(cliCtx client.Context, r *mux.Router) {
|
2020-06-12 19:45:07 +00:00
|
|
|
r.HandleFunc(fmt.Sprintf("/%s/parameters", types.ModuleName), queryParamsHandlerFn(cliCtx)).Methods("GET")
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func queryParamsHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
2020-06-12 19:45:07 +00:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryGetParams)
|
2020-06-12 19:45:07 +00:00
|
|
|
|
|
|
|
res, height, err := cliCtx.QueryWithData(route, nil)
|
|
|
|
if err != nil {
|
|
|
|
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cliCtx = cliCtx.WithHeight(height)
|
|
|
|
rest.PostProcessResponse(w, cliCtx, res)
|
|
|
|
}
|
|
|
|
}
|