2019-04-01 10:28:36 -07:00
|
|
|
package rest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
2019-04-04 07:36:39 -07:00
|
|
|
"github.com/gorilla/mux"
|
|
|
|
|
2019-04-01 10:28:36 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
2019-06-08 09:17:21 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/mint/internal/types"
|
2019-04-01 10:28:36 -07:00
|
|
|
)
|
|
|
|
|
2019-06-06 08:43:15 -07:00
|
|
|
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
|
2019-04-01 10:28:36 -07:00
|
|
|
r.HandleFunc(
|
|
|
|
"/minting/parameters",
|
2019-06-06 08:43:15 -07:00
|
|
|
queryParamsHandlerFn(cliCtx),
|
2019-04-01 10:28:36 -07:00
|
|
|
).Methods("GET")
|
|
|
|
|
|
|
|
r.HandleFunc(
|
|
|
|
"/minting/inflation",
|
2019-06-06 08:43:15 -07:00
|
|
|
queryInflationHandlerFn(cliCtx),
|
2019-04-01 10:28:36 -07:00
|
|
|
).Methods("GET")
|
|
|
|
|
|
|
|
r.HandleFunc(
|
|
|
|
"/minting/annual-provisions",
|
2019-06-06 08:43:15 -07:00
|
|
|
queryAnnualProvisionsHandlerFn(cliCtx),
|
2019-04-01 10:28:36 -07:00
|
|
|
).Methods("GET")
|
|
|
|
}
|
|
|
|
|
2019-06-06 08:43:15 -07:00
|
|
|
func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
2019-04-01 10:28:36 -07:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
2019-06-05 16:26:17 -07:00
|
|
|
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParameters)
|
2019-04-01 10:28:36 -07:00
|
|
|
|
2019-06-07 06:02:07 -07:00
|
|
|
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-01 09:48:13 -07:00
|
|
|
res, height, err := cliCtx.QueryWithData(route, nil)
|
2019-04-01 10:28:36 -07:00
|
|
|
if err != nil {
|
|
|
|
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-01 09:48:13 -07:00
|
|
|
cliCtx = cliCtx.WithHeight(height)
|
2019-06-06 08:43:15 -07:00
|
|
|
rest.PostProcessResponse(w, cliCtx, res)
|
2019-04-01 10:28:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 08:43:15 -07:00
|
|
|
func queryInflationHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
2019-04-01 10:28:36 -07:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
2019-06-05 16:26:17 -07:00
|
|
|
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryInflation)
|
2019-04-01 10:28:36 -07:00
|
|
|
|
2019-06-07 06:02:07 -07:00
|
|
|
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-01 09:48:13 -07:00
|
|
|
res, height, err := cliCtx.QueryWithData(route, nil)
|
2019-04-01 10:28:36 -07:00
|
|
|
if err != nil {
|
|
|
|
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-01 09:48:13 -07:00
|
|
|
cliCtx = cliCtx.WithHeight(height)
|
2019-06-06 08:43:15 -07:00
|
|
|
rest.PostProcessResponse(w, cliCtx, res)
|
2019-04-01 10:28:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 08:43:15 -07:00
|
|
|
func queryAnnualProvisionsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
2019-04-01 10:28:36 -07:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
2019-06-05 16:26:17 -07:00
|
|
|
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAnnualProvisions)
|
2019-04-01 10:28:36 -07:00
|
|
|
|
2019-06-07 06:02:07 -07:00
|
|
|
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-01 09:48:13 -07:00
|
|
|
res, height, err := cliCtx.QueryWithData(route, nil)
|
2019-04-01 10:28:36 -07:00
|
|
|
if err != nil {
|
|
|
|
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-01 09:48:13 -07:00
|
|
|
cliCtx = cliCtx.WithHeight(height)
|
2019-06-06 08:43:15 -07:00
|
|
|
rest.PostProcessResponse(w, cliCtx, res)
|
2019-04-01 10:28:36 -07:00
|
|
|
}
|
|
|
|
}
|