* Add types for staking grpc * Update module.go * Update staking query types * Add grpc query methods * Add delegation response to proto * Add queriers for delegations * Add queriers for unbonding * Add queriers for redelegations * Add cases for redelegations * Add test for grpc validators * Update staking types to proto * Update staking query proto * Add tests for grpc * Add tests for grpc pool, parameters * Fix lint issues * Add grpc redelegation tests * Add more tests * Add docs for query proto * Add docs for query types * Modify redel querier * Add debugging statements * Revert debugging * Fix proto lint errors * Add wrapper for keeper * Embed keeper in querier * Add more tests * Add tests for validator unbondings * Add redel tests * fix queryRedelegationsFromSrcValidator * Fix Redelegation tests * update godoc * Update args * Update tests with suite * Fix lint * Remove redundant types * Refactor tests * fix test * refactor query proto * Fix tests * address review comments * lint staking proto * add godoc * Update tests to table driven tests * add debugging * Fix grpc tests * address comments * address whitespace suggestions * Add more tests * add tests for invalid redels * update error messages * address review suggestions * add tests * move suite to keeper_test Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
112 lines
2.9 KiB
Go
112 lines
2.9 KiB
Go
package rest
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
|
"github.com/cosmos/cosmos-sdk/x/slashing/types"
|
|
)
|
|
|
|
func registerQueryRoutes(clientCtx client.Context, r *mux.Router) {
|
|
r.HandleFunc(
|
|
"/slashing/validators/{validatorPubKey}/signing_info",
|
|
signingInfoHandlerFn(clientCtx),
|
|
).Methods("GET")
|
|
|
|
r.HandleFunc(
|
|
"/slashing/signing_infos",
|
|
signingInfoHandlerListFn(clientCtx),
|
|
).Methods("GET")
|
|
|
|
r.HandleFunc(
|
|
"/slashing/parameters",
|
|
queryParamsHandlerFn(clientCtx),
|
|
).Methods("GET")
|
|
}
|
|
|
|
// http request handler to query signing info
|
|
func signingInfoHandlerFn(clientCtx client.Context) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
vars := mux.Vars(r)
|
|
pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, vars["validatorPubKey"])
|
|
if rest.CheckBadRequestError(w, err) {
|
|
return
|
|
}
|
|
|
|
clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
params := types.QuerySigningInfoRequest{ConsAddress: sdk.ConsAddress(pk.Address())}
|
|
|
|
bz, err := clientCtx.JSONMarshaler.MarshalJSON(params)
|
|
if rest.CheckBadRequestError(w, err) {
|
|
return
|
|
}
|
|
|
|
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QuerySigningInfo)
|
|
res, height, err := clientCtx.QueryWithData(route, bz)
|
|
if rest.CheckInternalServerError(w, err) {
|
|
return
|
|
}
|
|
|
|
clientCtx = clientCtx.WithHeight(height)
|
|
rest.PostProcessResponse(w, clientCtx, res)
|
|
}
|
|
}
|
|
|
|
// http request handler to query signing info
|
|
func signingInfoHandlerListFn(clientCtx client.Context) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
|
|
if rest.CheckBadRequestError(w, err) {
|
|
return
|
|
}
|
|
|
|
clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
params := types.NewQuerySigningInfosParams(page, limit)
|
|
bz, err := clientCtx.JSONMarshaler.MarshalJSON(params)
|
|
if rest.CheckInternalServerError(w, err) {
|
|
return
|
|
}
|
|
|
|
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QuerySigningInfos)
|
|
res, height, err := clientCtx.QueryWithData(route, bz)
|
|
if rest.CheckInternalServerError(w, err) {
|
|
return
|
|
}
|
|
|
|
clientCtx = clientCtx.WithHeight(height)
|
|
rest.PostProcessResponse(w, clientCtx, res)
|
|
}
|
|
}
|
|
|
|
func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
route := fmt.Sprintf("custom/%s/parameters", types.QuerierRoute)
|
|
|
|
res, height, err := clientCtx.QueryWithData(route, nil)
|
|
if rest.CheckInternalServerError(w, err) {
|
|
return
|
|
}
|
|
|
|
clientCtx = clientCtx.WithHeight(height)
|
|
rest.PostProcessResponse(w, clientCtx, res)
|
|
}
|
|
}
|