2018-04-23 08:30:54 -07:00
|
|
|
package rest
|
|
|
|
|
|
|
|
import (
|
2019-04-24 08:48:39 -07:00
|
|
|
"fmt"
|
2018-04-23 08:30:54 -07:00
|
|
|
"net/http"
|
2019-12-18 05:20:02 -08:00
|
|
|
"strconv"
|
2018-08-08 03:38:39 -07:00
|
|
|
"strings"
|
2018-04-23 08:30:54 -07:00
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/gorilla/mux"
|
|
|
|
|
2018-04-23 08:30:54 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-02-14 08:53:36 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
2018-04-23 08:30:54 -07:00
|
|
|
)
|
|
|
|
|
2019-06-06 08:43:15 -07:00
|
|
|
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
|
2018-10-20 13:25:50 -07:00
|
|
|
// Get all delegations from a delegator
|
2018-06-26 19:00:12 -07:00
|
|
|
r.HandleFunc(
|
2019-01-11 12:08:01 -08:00
|
|
|
"/staking/delegators/{delegatorAddr}/delegations",
|
2019-06-06 08:43:15 -07:00
|
|
|
delegatorDelegationsHandlerFn(cliCtx),
|
2018-10-20 13:25:50 -07:00
|
|
|
).Methods("GET")
|
|
|
|
|
|
|
|
// Get all unbonding delegations from a delegator
|
|
|
|
r.HandleFunc(
|
2019-01-11 12:08:01 -08:00
|
|
|
"/staking/delegators/{delegatorAddr}/unbonding_delegations",
|
2019-06-06 08:43:15 -07:00
|
|
|
delegatorUnbondingDelegationsHandlerFn(cliCtx),
|
2018-10-20 13:25:50 -07:00
|
|
|
).Methods("GET")
|
|
|
|
|
2018-08-13 15:06:48 -07:00
|
|
|
// Get all staking txs (i.e msgs) from a delegator
|
2018-08-08 03:38:39 -07:00
|
|
|
r.HandleFunc(
|
2019-01-11 12:08:01 -08:00
|
|
|
"/staking/delegators/{delegatorAddr}/txs",
|
2019-06-06 08:43:15 -07:00
|
|
|
delegatorTxsHandlerFn(cliCtx),
|
2018-06-26 19:00:12 -07:00
|
|
|
).Methods("GET")
|
|
|
|
|
2018-08-13 15:06:48 -07:00
|
|
|
// Query all validators that a delegator is bonded to
|
|
|
|
r.HandleFunc(
|
2019-01-11 12:08:01 -08:00
|
|
|
"/staking/delegators/{delegatorAddr}/validators",
|
2019-06-06 08:43:15 -07:00
|
|
|
delegatorValidatorsHandlerFn(cliCtx),
|
2018-08-13 15:06:48 -07:00
|
|
|
).Methods("GET")
|
|
|
|
|
|
|
|
// Query a validator that a delegator is bonded to
|
|
|
|
r.HandleFunc(
|
2019-01-11 12:08:01 -08:00
|
|
|
"/staking/delegators/{delegatorAddr}/validators/{validatorAddr}",
|
2019-06-06 08:43:15 -07:00
|
|
|
delegatorValidatorHandlerFn(cliCtx),
|
2018-08-13 15:06:48 -07:00
|
|
|
).Methods("GET")
|
|
|
|
|
|
|
|
// Query a delegation between a delegator and a validator
|
2018-06-26 19:00:12 -07:00
|
|
|
r.HandleFunc(
|
2019-01-11 12:08:01 -08:00
|
|
|
"/staking/delegators/{delegatorAddr}/delegations/{validatorAddr}",
|
2019-06-06 08:43:15 -07:00
|
|
|
delegationHandlerFn(cliCtx),
|
2018-06-26 19:00:12 -07:00
|
|
|
).Methods("GET")
|
|
|
|
|
2018-09-13 14:23:44 -07:00
|
|
|
// Query all unbonding delegations between a delegator and a validator
|
2018-05-24 08:14:10 -07:00
|
|
|
r.HandleFunc(
|
2019-01-11 12:08:01 -08:00
|
|
|
"/staking/delegators/{delegatorAddr}/unbonding_delegations/{validatorAddr}",
|
2019-06-06 08:43:15 -07:00
|
|
|
unbondingDelegationHandlerFn(cliCtx),
|
2018-05-24 08:14:10 -07:00
|
|
|
).Methods("GET")
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2018-12-18 13:43:41 -08:00
|
|
|
// Query redelegations (filters in query params)
|
|
|
|
r.HandleFunc(
|
2019-01-11 12:08:01 -08:00
|
|
|
"/staking/redelegations",
|
2019-06-06 08:43:15 -07:00
|
|
|
redelegationsHandlerFn(cliCtx),
|
2018-12-18 13:43:41 -08:00
|
|
|
).Methods("GET")
|
|
|
|
|
2018-08-13 15:06:48 -07:00
|
|
|
// Get all validators
|
2018-05-28 23:07:03 -07:00
|
|
|
r.HandleFunc(
|
2019-01-11 12:08:01 -08:00
|
|
|
"/staking/validators",
|
2019-06-06 08:43:15 -07:00
|
|
|
validatorsHandlerFn(cliCtx),
|
2018-05-28 23:07:03 -07:00
|
|
|
).Methods("GET")
|
2018-08-08 03:38:39 -07:00
|
|
|
|
2018-08-13 15:06:48 -07:00
|
|
|
// Get a single validator info
|
2018-08-08 03:38:39 -07:00
|
|
|
r.HandleFunc(
|
2019-01-11 12:08:01 -08:00
|
|
|
"/staking/validators/{validatorAddr}",
|
2019-06-06 08:43:15 -07:00
|
|
|
validatorHandlerFn(cliCtx),
|
2018-08-08 03:38:39 -07:00
|
|
|
).Methods("GET")
|
2018-08-13 15:06:48 -07:00
|
|
|
|
2018-11-05 16:42:49 -08:00
|
|
|
// Get all delegations to a validator
|
2018-10-23 01:25:53 -07:00
|
|
|
r.HandleFunc(
|
2019-01-11 12:08:01 -08:00
|
|
|
"/staking/validators/{validatorAddr}/delegations",
|
2019-06-06 08:43:15 -07:00
|
|
|
validatorDelegationsHandlerFn(cliCtx),
|
2018-10-23 01:25:53 -07:00
|
|
|
).Methods("GET")
|
|
|
|
|
2018-10-20 12:30:07 -07:00
|
|
|
// Get all unbonding delegations from a validator
|
|
|
|
r.HandleFunc(
|
2019-01-11 12:08:01 -08:00
|
|
|
"/staking/validators/{validatorAddr}/unbonding_delegations",
|
2019-06-06 08:43:15 -07:00
|
|
|
validatorUnbondingDelegationsHandlerFn(cliCtx),
|
2018-10-20 12:30:07 -07:00
|
|
|
).Methods("GET")
|
|
|
|
|
2019-12-18 05:20:02 -08:00
|
|
|
// Get HistoricalInfo at a given height
|
|
|
|
r.HandleFunc(
|
|
|
|
"/staking/historical_info/{height}",
|
|
|
|
historicalInfoHandlerFn(cliCtx),
|
|
|
|
).Methods("GET")
|
|
|
|
|
2018-08-21 08:32:54 -07:00
|
|
|
// Get the current state of the staking pool
|
|
|
|
r.HandleFunc(
|
2019-01-11 12:08:01 -08:00
|
|
|
"/staking/pool",
|
2019-06-06 08:43:15 -07:00
|
|
|
poolHandlerFn(cliCtx),
|
2018-08-21 08:32:54 -07:00
|
|
|
).Methods("GET")
|
|
|
|
|
|
|
|
// Get the current staking parameter values
|
|
|
|
r.HandleFunc(
|
2019-01-11 12:08:01 -08:00
|
|
|
"/staking/parameters",
|
2019-06-06 08:43:15 -07:00
|
|
|
paramsHandlerFn(cliCtx),
|
2018-08-21 08:32:54 -07:00
|
|
|
).Methods("GET")
|
|
|
|
|
2018-04-23 08:30:54 -07:00
|
|
|
}
|
|
|
|
|
2018-08-08 03:38:39 -07:00
|
|
|
// HTTP request handler to query a delegator delegations
|
2019-06-06 08:43:15 -07:00
|
|
|
func delegatorDelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|
|
|
return queryDelegator(cliCtx, fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryDelegatorDelegations))
|
2018-10-20 13:25:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// HTTP request handler to query a delegator unbonding delegations
|
2019-06-06 08:43:15 -07:00
|
|
|
func delegatorUnbondingDelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|
|
|
return queryDelegator(cliCtx, "custom/staking/delegatorUnbondingDelegations")
|
2018-10-20 13:25:50 -07:00
|
|
|
}
|
|
|
|
|
2018-08-08 03:38:39 -07:00
|
|
|
// HTTP request handler to query all staking txs (msgs) from a delegator
|
2019-06-06 08:43:15 -07:00
|
|
|
func delegatorTxsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
2018-08-08 03:38:39 -07:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var typesQuerySlice []string
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
delegatorAddr := vars["delegatorAddr"]
|
|
|
|
|
|
|
|
_, err := sdk.AccAddressFromBech32(delegatorAddr)
|
2020-04-01 00:50:22 -07:00
|
|
|
if rest.CheckBadRequestError(w, err) {
|
2018-04-23 08:30:54 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-06-07 06:02:07 -07:00
|
|
|
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-08 03:38:39 -07:00
|
|
|
typesQuery := r.URL.Query().Get("type")
|
|
|
|
trimmedQuery := strings.TrimSpace(typesQuery)
|
|
|
|
if len(trimmedQuery) != 0 {
|
|
|
|
typesQuerySlice = strings.Split(trimmedQuery, " ")
|
|
|
|
}
|
|
|
|
|
|
|
|
noQuery := len(typesQuerySlice) == 0
|
|
|
|
isBondTx := contains(typesQuerySlice, "bond")
|
|
|
|
isUnbondTx := contains(typesQuerySlice, "unbond")
|
|
|
|
isRedTx := contains(typesQuerySlice, "redelegate")
|
2019-06-26 09:03:25 -07:00
|
|
|
|
|
|
|
var (
|
|
|
|
txs []*sdk.SearchTxsResult
|
|
|
|
actions []string
|
|
|
|
)
|
2018-08-08 03:38:39 -07:00
|
|
|
|
|
|
|
switch {
|
|
|
|
case isBondTx:
|
2019-06-05 16:26:17 -07:00
|
|
|
actions = append(actions, types.MsgDelegate{}.Type())
|
2019-06-26 09:03:25 -07:00
|
|
|
|
2018-08-08 03:38:39 -07:00
|
|
|
case isUnbondTx:
|
2019-06-05 16:26:17 -07:00
|
|
|
actions = append(actions, types.MsgUndelegate{}.Type())
|
2019-06-26 09:03:25 -07:00
|
|
|
|
2018-08-08 03:38:39 -07:00
|
|
|
case isRedTx:
|
2019-06-05 16:26:17 -07:00
|
|
|
actions = append(actions, types.MsgBeginRedelegate{}.Type())
|
2019-06-26 09:03:25 -07:00
|
|
|
|
2018-08-08 03:38:39 -07:00
|
|
|
case noQuery:
|
2019-06-05 16:26:17 -07:00
|
|
|
actions = append(actions, types.MsgDelegate{}.Type())
|
|
|
|
actions = append(actions, types.MsgUndelegate{}.Type())
|
|
|
|
actions = append(actions, types.MsgBeginRedelegate{}.Type())
|
2019-06-26 09:03:25 -07:00
|
|
|
|
2018-08-08 03:38:39 -07:00
|
|
|
default:
|
2018-06-26 19:00:12 -07:00
|
|
|
w.WriteHeader(http.StatusNoContent)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-08 03:38:39 -07:00
|
|
|
for _, action := range actions {
|
2019-06-06 08:43:15 -07:00
|
|
|
foundTxs, errQuery := queryTxs(cliCtx, action, delegatorAddr)
|
2020-04-01 00:50:22 -07:00
|
|
|
if rest.CheckInternalServerError(w, errQuery) {
|
|
|
|
return
|
2018-08-08 03:38:39 -07:00
|
|
|
}
|
2019-05-04 04:09:03 -07:00
|
|
|
txs = append(txs, foundTxs)
|
2018-07-04 14:07:06 -07:00
|
|
|
}
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2019-06-06 08:43:15 -07:00
|
|
|
res, err := cliCtx.Codec.MarshalJSON(txs)
|
2020-04-01 00:50:22 -07:00
|
|
|
if rest.CheckInternalServerError(w, err) {
|
2018-06-26 19:00:12 -07:00
|
|
|
return
|
|
|
|
}
|
2019-06-06 08:43:15 -07:00
|
|
|
|
2019-08-03 06:56:15 -07:00
|
|
|
rest.PostProcessResponseBare(w, cliCtx, res)
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-08 03:38:39 -07:00
|
|
|
// HTTP request handler to query an unbonding-delegation
|
2019-06-06 08:43:15 -07:00
|
|
|
func unbondingDelegationHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|
|
|
return queryBonds(cliCtx, "custom/staking/unbondingDelegation")
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
|
|
|
|
2018-12-18 13:43:41 -08:00
|
|
|
// HTTP request handler to query redelegations
|
2019-06-06 08:43:15 -07:00
|
|
|
func redelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
2018-12-18 13:43:41 -08:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
2019-06-05 16:26:17 -07:00
|
|
|
var params types.QueryRedelegationParams
|
2018-12-18 13:43:41 -08:00
|
|
|
|
2019-06-07 06:02:07 -07:00
|
|
|
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-12-18 13:43:41 -08:00
|
|
|
bechDelegatorAddr := r.URL.Query().Get("delegator")
|
|
|
|
bechSrcValidatorAddr := r.URL.Query().Get("validator_from")
|
|
|
|
bechDstValidatorAddr := r.URL.Query().Get("validator_to")
|
|
|
|
|
|
|
|
if len(bechDelegatorAddr) != 0 {
|
|
|
|
delegatorAddr, err := sdk.AccAddressFromBech32(bechDelegatorAddr)
|
2020-04-01 00:50:22 -07:00
|
|
|
if rest.CheckBadRequestError(w, err) {
|
2018-12-18 13:43:41 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
params.DelegatorAddr = delegatorAddr
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(bechSrcValidatorAddr) != 0 {
|
|
|
|
srcValidatorAddr, err := sdk.ValAddressFromBech32(bechSrcValidatorAddr)
|
2020-04-01 00:50:22 -07:00
|
|
|
if rest.CheckBadRequestError(w, err) {
|
2018-12-18 13:43:41 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
params.SrcValidatorAddr = srcValidatorAddr
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(bechDstValidatorAddr) != 0 {
|
|
|
|
dstValidatorAddr, err := sdk.ValAddressFromBech32(bechDstValidatorAddr)
|
2020-04-01 00:50:22 -07:00
|
|
|
if rest.CheckBadRequestError(w, err) {
|
2018-12-18 13:43:41 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
params.DstValidatorAddr = dstValidatorAddr
|
|
|
|
}
|
|
|
|
|
2019-06-06 08:43:15 -07:00
|
|
|
bz, err := cliCtx.Codec.MarshalJSON(params)
|
2020-04-01 00:50:22 -07:00
|
|
|
if rest.CheckBadRequestError(w, err) {
|
2018-12-18 13:43:41 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-01 09:48:13 -07:00
|
|
|
res, height, err := cliCtx.QueryWithData("custom/staking/redelegations", bz)
|
2020-04-01 00:50:22 -07:00
|
|
|
if rest.CheckInternalServerError(w, err) {
|
2018-12-18 13:43:41 -08:00
|
|
|
return
|
|
|
|
}
|
2019-06-06 08:43:15 -07:00
|
|
|
|
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)
|
2018-12-18 13:43:41 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-19 15:49:10 -07:00
|
|
|
// HTTP request handler to query a delegation
|
2019-06-06 08:43:15 -07:00
|
|
|
func delegationHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|
|
|
return queryBonds(cliCtx, fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryDelegation))
|
2018-08-08 03:38:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// HTTP request handler to query all delegator bonded validators
|
2019-06-06 08:43:15 -07:00
|
|
|
func delegatorValidatorsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|
|
|
return queryDelegator(cliCtx, "custom/staking/delegatorValidators")
|
2018-08-08 03:38:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// HTTP request handler to get information from a currently bonded validator
|
2019-06-06 08:43:15 -07:00
|
|
|
func delegatorValidatorHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|
|
|
return queryBonds(cliCtx, "custom/staking/delegatorValidator")
|
2018-04-23 08:30:54 -07:00
|
|
|
}
|
2018-05-28 23:07:03 -07:00
|
|
|
|
2018-09-13 14:23:44 -07:00
|
|
|
// HTTP request handler to query list of validators
|
2019-06-06 08:43:15 -07:00
|
|
|
func validatorsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
2018-05-28 23:07:03 -07:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
2019-05-09 10:38:15 -07:00
|
|
|
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
|
2020-04-01 00:50:22 -07:00
|
|
|
if rest.CheckBadRequestError(w, err) {
|
2019-04-24 08:48:39 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-06-07 06:02:07 -07:00
|
|
|
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-04-24 08:48:39 -07:00
|
|
|
status := r.FormValue("status")
|
|
|
|
if status == "" {
|
|
|
|
status = sdk.BondStatusBonded
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
params := types.NewQueryValidatorsParams(page, limit, status)
|
2019-06-06 08:43:15 -07:00
|
|
|
bz, err := cliCtx.Codec.MarshalJSON(params)
|
2020-04-01 00:50:22 -07:00
|
|
|
if rest.CheckBadRequestError(w, err) {
|
2019-04-24 08:48:39 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryValidators)
|
2019-07-01 09:48:13 -07:00
|
|
|
res, height, err := cliCtx.QueryWithData(route, bz)
|
2020-04-01 00:50:22 -07:00
|
|
|
if rest.CheckInternalServerError(w, err) {
|
2018-05-28 23:07:03 -07:00
|
|
|
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)
|
2018-05-28 23:07:03 -07:00
|
|
|
}
|
|
|
|
}
|
2018-08-08 03:38:39 -07:00
|
|
|
|
|
|
|
// HTTP request handler to query the validator information from a given validator address
|
2019-06-06 08:43:15 -07:00
|
|
|
func validatorHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|
|
|
return queryValidator(cliCtx, "custom/staking/validator")
|
2018-10-20 11:31:20 -07:00
|
|
|
}
|
2018-08-08 03:38:39 -07:00
|
|
|
|
2018-10-23 01:25:53 -07:00
|
|
|
// HTTP request handler to query all unbonding delegations from a validator
|
2019-06-06 08:43:15 -07:00
|
|
|
func validatorDelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|
|
|
return queryValidator(cliCtx, fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryValidatorDelegations))
|
2018-10-23 01:25:53 -07:00
|
|
|
}
|
|
|
|
|
2018-10-20 12:30:07 -07:00
|
|
|
// HTTP request handler to query all unbonding delegations from a validator
|
2019-06-06 08:43:15 -07:00
|
|
|
func validatorUnbondingDelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|
|
|
return queryValidator(cliCtx, "custom/staking/validatorUnbondingDelegations")
|
2018-10-20 12:30:07 -07:00
|
|
|
}
|
2018-08-08 03:38:39 -07:00
|
|
|
|
2019-12-18 05:20:02 -08:00
|
|
|
// HTTP request handler to query historical info at a given height
|
|
|
|
func historicalInfoHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
heightStr := vars["height"]
|
|
|
|
height, err := strconv.ParseInt(heightStr, 10, 64)
|
|
|
|
if err != nil || height < 0 {
|
|
|
|
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("Must provide non-negative integer for height: %v", err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
params := types.NewQueryHistoricalInfoParams(height)
|
|
|
|
bz, err := cliCtx.Codec.MarshalJSON(params)
|
2020-04-01 00:50:22 -07:00
|
|
|
if rest.CheckInternalServerError(w, err) {
|
2019-12-18 05:20:02 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryHistoricalInfo)
|
|
|
|
res, height, err := cliCtx.QueryWithData(route, bz)
|
2020-04-01 00:50:22 -07:00
|
|
|
if rest.CheckBadRequestError(w, err) {
|
2019-12-18 05:20:02 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cliCtx = cliCtx.WithHeight(height)
|
|
|
|
rest.PostProcessResponse(w, cliCtx, res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-21 08:32:54 -07:00
|
|
|
// HTTP request handler to query the pool information
|
2019-06-06 08:43:15 -07:00
|
|
|
func poolHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
2018-08-21 08:32:54 -07:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
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("custom/staking/pool", nil)
|
2020-04-01 00:50:22 -07:00
|
|
|
if rest.CheckInternalServerError(w, err) {
|
2018-08-21 08:32:54 -07:00
|
|
|
return
|
|
|
|
}
|
2019-06-06 08:43:15 -07:00
|
|
|
|
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)
|
2018-08-21 08:32:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// HTTP request handler to query the staking params values
|
2019-06-06 08:43:15 -07:00
|
|
|
func paramsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
2018-08-21 08:32:54 -07:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
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("custom/staking/parameters", nil)
|
2020-04-01 00:50:22 -07:00
|
|
|
if rest.CheckInternalServerError(w, err) {
|
2018-08-21 08:32:54 -07:00
|
|
|
return
|
|
|
|
}
|
2019-06-06 08:43:15 -07:00
|
|
|
|
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)
|
2018-08-21 08:32:54 -07:00
|
|
|
}
|
|
|
|
}
|