From 31e185c6320586ff90ceb06dad708127a94aac30 Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Mon, 3 Feb 2020 10:41:28 -0500 Subject: [PATCH] [R4R] cdp rest fixes (#360) * fix: use correct path for cdp queries * fix: avoid params being confused for cdp denom * fix: use consistent terminology * fix: struct tag mismatch for repayment * fix: use plural when querying multiple cdps * fix: use correct type for query by ratio * wip: refactor cdp query paths * wip: routing queries * fix: route prefixes * wip: address review comments * Update x/cdp/client/rest/query.go Co-Authored-By: Ruaridh * use post instead of put Co-authored-by: Ruaridh --- x/cdp/client/rest/query.go | 16 ++++++++-------- x/cdp/client/rest/rest.go | 4 ++-- x/cdp/client/rest/tx.go | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/x/cdp/client/rest/query.go b/x/cdp/client/rest/query.go index be94cc78..7f3f05a8 100644 --- a/x/cdp/client/rest/query.go +++ b/x/cdp/client/rest/query.go @@ -16,11 +16,11 @@ import ( // define routes that get registered by the main application func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) { - r.HandleFunc(fmt.Sprintf("/cdp/{%s}/{%s}", types.RestOwner, types.RestCollateralDenom), queryCdpHandlerFn(cliCtx)).Methods("GET") - r.HandleFunc(fmt.Sprintf("/cdp/{%s}", types.RestCollateralDenom), queryCdpsHandlerFn(cliCtx)).Methods("GET") - r.HandleFunc(fmt.Sprintf("/cdp/{%s}/ratio/{%s}", types.RestCollateralDenom, types.RestRatio), queryCdpsByRatioHandlerFn(cliCtx)).Methods("GET") - r.HandleFunc(fmt.Sprintf("/cdp/deposits/{%s}/{%s}", types.RestOwner, types.RestCollateralDenom), queryCdpDepositsHandlerFn(cliCtx)).Methods("GET") - r.HandleFunc("/cdp/params", getParamsHandlerFn(cliCtx)).Methods("GET") + r.HandleFunc("/cdp/parameters", getParamsHandlerFn(cliCtx)).Methods("GET") + r.HandleFunc(fmt.Sprintf("/cdp/cdps/cdp/{%s}/{%s}", types.RestOwner, types.RestCollateralDenom), queryCdpHandlerFn(cliCtx)).Methods("GET") + r.HandleFunc(fmt.Sprintf("/cdp/cdps/denom/{%s}", types.RestCollateralDenom), queryCdpsHandlerFn(cliCtx)).Methods("GET") + r.HandleFunc(fmt.Sprintf("/cdp/cdps/ratio/{%s}/{%s}", types.RestCollateralDenom, types.RestRatio), queryCdpsByRatioHandlerFn(cliCtx)).Methods("GET") + r.HandleFunc(fmt.Sprintf("/cdp/cdps/cdp/deposits/{%s}/{%s}", types.RestOwner, types.RestCollateralDenom), queryCdpDepositsHandlerFn(cliCtx)).Methods("GET") } func queryCdpHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { @@ -43,7 +43,7 @@ func queryCdpHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s", types.QueryGetCdp), bz) + res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/cdp/%s", types.QueryGetCdp), bz) if err != nil { rest.WriteErrorResponse(w, http.StatusNotFound, err.Error()) return @@ -68,7 +68,7 @@ func queryCdpsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s", types.QueryGetCdps), bz) + res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/cdp/%s", types.QueryGetCdps), bz) if err != nil { rest.WriteErrorResponse(w, http.StatusNotFound, err.Error()) return @@ -99,7 +99,7 @@ func queryCdpsByRatioHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s", types.QueryGetCdps), bz) + res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/cdp/%s", types.QueryGetCdpsByCollateralization), bz) if err != nil { rest.WriteErrorResponse(w, http.StatusNotFound, err.Error()) return diff --git a/x/cdp/client/rest/rest.go b/x/cdp/client/rest/rest.go index d626841a..287c0613 100644 --- a/x/cdp/client/rest/rest.go +++ b/x/cdp/client/rest/rest.go @@ -17,7 +17,7 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) { // PostCdpReq defines the properties of cdp request's body. type PostCdpReq struct { BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` - Owner sdk.AccAddress `json:"owner" yaml:"owner"` + Sender sdk.AccAddress `json:"sender" yaml:"sender"` Collateral sdk.Coins `json:"collateral" yaml:"collateral"` Principal sdk.Coins `json:"principal" yaml:"principal"` } @@ -51,5 +51,5 @@ type PostRepayReq struct { BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` Owner sdk.AccAddress `json:"owner" yaml:"owner"` Denom string `json:"denom" yaml:"denom"` - Payment sdk.Coins `json:"principal" yaml:"principal"` + Payment sdk.Coins `json:"payment" yaml:"payment"` } diff --git a/x/cdp/client/rest/tx.go b/x/cdp/client/rest/tx.go index efef85ef..500e688e 100644 --- a/x/cdp/client/rest/tx.go +++ b/x/cdp/client/rest/tx.go @@ -14,11 +14,11 @@ import ( ) func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) { - r.HandleFunc("/cdp", postCdpHandlerFn(cliCtx)).Methods("PUT") - r.HandleFunc("/cdp/{owner}/{denom}/deposits", postDepositHandlerFn(cliCtx)).Methods("PUT") - r.HandleFunc("/cdp/{owner}/{denom}/withdraw", postWithdrawHandlerFn(cliCtx)).Methods("PUT") - r.HandleFunc("/cdp/{owner}/{denom}/draw", postDrawHandlerFn(cliCtx)).Methods("PUT") - r.HandleFunc("/cdp/{owner}/{denom}/wipe", postRepayHandlerFn(cliCtx)).Methods("PUT") + r.HandleFunc("/cdp", postCdpHandlerFn(cliCtx)).Methods("POST") + r.HandleFunc("/cdp/{owner}/{denom}/deposits", postDepositHandlerFn(cliCtx)).Methods("POST") + r.HandleFunc("/cdp/{owner}/{denom}/withdraw", postWithdrawHandlerFn(cliCtx)).Methods("POST") + r.HandleFunc("/cdp/{owner}/{denom}/draw", postDrawHandlerFn(cliCtx)).Methods("POST") + r.HandleFunc("/cdp/{owner}/{denom}/repay", postRepayHandlerFn(cliCtx)).Methods("POST") } @@ -36,7 +36,7 @@ func postCdpHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { // Create and return msg msg := types.NewMsgCreateCDP( - requestBody.Owner, + requestBody.Sender, requestBody.Collateral, requestBody.Principal, )