Skip to content

Commit

Permalink
fix: add missing rest endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
snobbee committed Nov 6, 2023
1 parent 0f064e0 commit 7c5ed10
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
90 changes: 89 additions & 1 deletion x/clp/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ func registerQueryRoutes(cliCtx client.Context, r *mux.Router) {
"/clp/params",
getParamsHandler(cliCtx),
).Methods("GET")
r.HandleFunc(
"/clp/getRewardsBucket",
getRewardsBucketHandler(cliCtx),
).Methods("GET")
r.HandleFunc(
"/clp/getRewardsBuckets",
getRewardsBucketsHandler(cliCtx),
).Methods("GET")
}

func getPoolHandler(cliCtx client.Context) http.HandlerFunc {
Expand Down Expand Up @@ -221,7 +229,7 @@ func getAssetsHandler(cliCtx client.Context) http.HandlerFunc {
}
}

//http://localhost:1317/clp/getLpList?symbol=catk
// http://localhost:1317/clp/getLpList?symbol=catk
func getLpListHandler(cliCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
Expand Down Expand Up @@ -334,3 +342,83 @@ func getParamsHandler(cliCtx client.Context) http.HandlerFunc {
rest.PostProcessResponse(w, cliCtx, res)
}
}

func getRewardsBucketHandler(cliCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}
//Generate Router
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryRewardsBucket)
//Generate Params
var params types.RewardsBucketReq
params.Denom = r.URL.Query().Get("denom")

bz, err := cliCtx.LegacyAmino.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
res, height, err := cliCtx.QueryWithData(route, bz)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, res)
}
}

func getRewardsBucketsHandler(cliCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}

route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryRewardsBuckets)

var err error
var limit, offset uint64

if r.URL.Query().Get("limit") != "" {
limit, err = strconv.ParseUint(r.URL.Query().Get("limit"), 10, 64)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
}

if r.URL.Query().Get("offset") != "" {
offset, err = strconv.ParseUint(r.URL.Query().Get("offset"), 10, 64)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
}

params := types.AllRewardsBucketReq{
Pagination: &query.PageRequest{
Limit: limit,
Offset: offset,
},
}

bz, err := cliCtx.LegacyAmino.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

res, height, err := cliCtx.QueryWithData(route, bz)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, res)
}
}
2 changes: 2 additions & 0 deletions x/clp/types/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const (
QueryParams = "params"
QueryRewardParams = "rewardParams"
QueryPmtpParams = "pmtpParams"
QueryRewardsBucket = "rewardsBucket"
QueryRewardsBuckets = "allRewardsBuckets"
)

func NewQueryReqGetPool(symbol string) PoolReq {
Expand Down

0 comments on commit 7c5ed10

Please sign in to comment.