From 923ad0afe020a7056a7e10db72b3113e5d4b17a6 Mon Sep 17 00:00:00 2001 From: Cory Levinson Date: Mon, 26 Oct 2020 18:02:29 -0700 Subject: [PATCH 1/9] add deprecation headers for legacy rest endpoints --- client/docs/swagger-ui/swagger-ui-bundle.js | 2 +- client/docs/swagger_legacy.yaml | 2 +- client/legacy_rest.go | 9 +++++++++ x/auth/client/rest/query.go | 8 ++++++++ x/auth/client/rest/rest.go | 3 +-- x/bank/client/rest/query.go | 5 +++++ x/bank/client/rest/tx.go | 2 ++ x/distribution/client/rest/query.go | 6 ++++++ x/distribution/client/rest/rest.go | 2 ++ x/distribution/client/rest/tx.go | 10 ++++++++++ x/evidence/client/rest/query.go | 4 ++++ x/gov/client/rest/query.go | 18 ++++++++++++++++++ x/gov/client/rest/tx.go | 6 ++++++ x/mint/client/rest/query.go | 6 ++++++ x/params/client/rest/rest.go | 2 ++ x/slashing/client/rest/query.go | 6 ++++++ x/slashing/client/rest/tx.go | 2 ++ x/staking/client/rest/query.go | 12 ++++++++++++ x/staking/client/rest/tx.go | 6 ++++++ x/staking/client/rest/utils.go | 6 ++++++ x/upgrade/client/rest/query.go | 4 ++++ x/upgrade/client/rest/tx.go | 4 ++++ 22 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 client/legacy_rest.go diff --git a/client/docs/swagger-ui/swagger-ui-bundle.js b/client/docs/swagger-ui/swagger-ui-bundle.js index 4491b4b28445..07eceace9377 100644 --- a/client/docs/swagger-ui/swagger-ui-bundle.js +++ b/client/docs/swagger-ui/swagger-ui-bundle.js @@ -41773,4 +41773,4 @@ }, o.resolve = i, e.exports = o, o.id = 1058 }]) }); -//# sourceMappingURL=swagger-ui-bundle.js.map \ No newline at end of file +//# sourceMappingURL=swagger-ui-bundle.js.map diff --git a/client/docs/swagger_legacy.yaml b/client/docs/swagger_legacy.yaml index 6e996d42cd78..fe00efa48493 100644 --- a/client/docs/swagger_legacy.yaml +++ b/client/docs/swagger_legacy.yaml @@ -2595,4 +2595,4 @@ definitions: total: type: array items: - $ref: "#/definitions/Coin" \ No newline at end of file + $ref: "#/definitions/Coin" diff --git a/client/legacy_rest.go b/client/legacy_rest.go new file mode 100644 index 000000000000..c51bc3bad09d --- /dev/null +++ b/client/legacy_rest.go @@ -0,0 +1,9 @@ +package client + +import "net/http" + +func AddDeprecationHeaders(rw http.ResponseWriter) http.ResponseWriter { + rw.Header().Set("Deprecation", "true") + rw.Header().Set("Link", "; rel=\"deprecation\"") + return rw +} diff --git a/x/auth/client/rest/query.go b/x/auth/client/rest/query.go index c40fc5530d77..8da10078f76e 100644 --- a/x/auth/client/rest/query.go +++ b/x/auth/client/rest/query.go @@ -19,6 +19,8 @@ import ( // query accountREST Handler func QueryAccountRequestHandlerFn(storeName string, clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) bech32addr := vars["address"] @@ -58,6 +60,8 @@ func QueryAccountRequestHandlerFn(storeName string, clientCtx client.Context) ht // otherwise the transactions are searched for by events. func QueryTxsRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + err := r.ParseForm() if err != nil { rest.WriteErrorResponse( @@ -110,6 +114,8 @@ func QueryTxsRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { // by hash in a committed block. func QueryTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) hashHexStr := vars["hash"] @@ -146,6 +152,8 @@ func QueryTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { func queryParamsHandler(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) if !ok { return diff --git a/x/auth/client/rest/rest.go b/x/auth/client/rest/rest.go index d3106edca229..213b99c8102d 100644 --- a/x/auth/client/rest/rest.go +++ b/x/auth/client/rest/rest.go @@ -1,9 +1,8 @@ package rest import ( - "github.com/gorilla/mux" - "github.com/cosmos/cosmos-sdk/client" + "github.com/gorilla/mux" ) // REST query and parameter values diff --git a/x/bank/client/rest/query.go b/x/bank/client/rest/query.go index 7c88c790f83c..1c2f63d6a44b 100644 --- a/x/bank/client/rest/query.go +++ b/x/bank/client/rest/query.go @@ -16,6 +16,7 @@ import ( // account balances or a specific balance by denomination. func QueryBalancesRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) w.Header().Set("Content-Type", "application/json") vars := mux.Vars(r) @@ -63,6 +64,8 @@ func QueryBalancesRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { // HTTP request handler to query the total supply of coins func totalSupplyHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + _, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0) if rest.CheckBadRequestError(w, err) { return @@ -94,6 +97,8 @@ func totalSupplyHandlerFn(clientCtx client.Context) http.HandlerFunc { // HTTP request handler to query the supply of a single denom func supplyOfHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + denom := mux.Vars(r)["denom"] clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) if !ok { diff --git a/x/bank/client/rest/tx.go b/x/bank/client/rest/tx.go index e630710dff22..1bbdbf0cd04e 100644 --- a/x/bank/client/rest/tx.go +++ b/x/bank/client/rest/tx.go @@ -22,6 +22,8 @@ type SendReq struct { // transaction. func NewSendRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) bech32Addr := vars["address"] diff --git a/x/distribution/client/rest/query.go b/x/distribution/client/rest/query.go index 0fb923afc94d..a49cac5a5339 100644 --- a/x/distribution/client/rest/query.go +++ b/x/distribution/client/rest/query.go @@ -68,6 +68,8 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) { // HTTP request handler to query the total rewards balance from all delegations func delegatorRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) if !ok { return @@ -99,6 +101,8 @@ func delegatorRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { // HTTP request handler to query a delegation rewards func delegationRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) if !ok { return @@ -121,6 +125,8 @@ func delegationRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { // HTTP request handler to query a delegation rewards func delegatorWithdrawalAddrHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + delegatorAddr, ok := checkDelegatorAddressVar(w, r) if !ok { return diff --git a/x/distribution/client/rest/rest.go b/x/distribution/client/rest/rest.go index 0269e9261188..e2003ed015b7 100644 --- a/x/distribution/client/rest/rest.go +++ b/x/distribution/client/rest/rest.go @@ -29,6 +29,8 @@ func ProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler { func postProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var req CommunityPoolSpendProposalReq if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return diff --git a/x/distribution/client/rest/tx.go b/x/distribution/client/rest/tx.go index 675be4af1abc..8d8ced41d505 100644 --- a/x/distribution/client/rest/tx.go +++ b/x/distribution/client/rest/tx.go @@ -63,6 +63,8 @@ func registerTxHandlers(clientCtx client.Context, r *mux.Router) { func newWithdrawDelegatorRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var req withdrawRewardsReq if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return @@ -90,6 +92,8 @@ func newWithdrawDelegatorRewardsHandlerFn(clientCtx client.Context) http.Handler func newWithdrawDelegationRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var req withdrawRewardsReq if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return @@ -122,6 +126,8 @@ func newWithdrawDelegationRewardsHandlerFn(clientCtx client.Context) http.Handle func newSetDelegatorWithdrawalAddrHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var req setWithdrawalAddrReq if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return @@ -149,6 +155,8 @@ func newSetDelegatorWithdrawalAddrHandlerFn(clientCtx client.Context) http.Handl func newWithdrawValidatorRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var req withdrawRewardsReq if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return @@ -177,6 +185,8 @@ func newWithdrawValidatorRewardsHandlerFn(clientCtx client.Context) http.Handler func newFundCommunityPoolHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var req fundCommunityPoolReq if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return diff --git a/x/evidence/client/rest/query.go b/x/evidence/client/rest/query.go index 21ae8b7bb306..94c4aecd6249 100644 --- a/x/evidence/client/rest/query.go +++ b/x/evidence/client/rest/query.go @@ -27,6 +27,8 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) { func queryEvidenceHandler(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) evidenceHash := vars[RestParamEvidenceHash] @@ -66,6 +68,8 @@ func queryEvidenceHandler(clientCtx client.Context) http.HandlerFunc { func queryAllEvidenceHandler(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + _, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0) if rest.CheckBadRequestError(w, err) { return diff --git a/x/gov/client/rest/query.go b/x/gov/client/rest/query.go index ffdbd8bc0290..d198f4b5a947 100644 --- a/x/gov/client/rest/query.go +++ b/x/gov/client/rest/query.go @@ -28,6 +28,8 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) { func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) paramType := vars[RestParamsType] @@ -48,6 +50,8 @@ func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc { func queryProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -86,6 +90,8 @@ func queryProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { func queryDepositsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -135,6 +141,8 @@ func queryDepositsHandlerFn(clientCtx client.Context) http.HandlerFunc { func queryProposerHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -159,6 +167,8 @@ func queryProposerHandlerFn(clientCtx client.Context) http.HandlerFunc { func queryDepositHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) strProposalID := vars[RestProposalID] bechDepositorAddr := vars[RestDepositor] @@ -235,6 +245,8 @@ func queryDepositHandlerFn(clientCtx client.Context) http.HandlerFunc { func queryVoteHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) strProposalID := vars[RestProposalID] bechVoterAddr := vars[RestVoter] @@ -313,6 +325,8 @@ func queryVoteHandlerFn(clientCtx client.Context) http.HandlerFunc { // todo: Split this functionality into helper functions to remove the above func queryVotesOnProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + _, page, limit, err := rest.ParseHTTPArgs(r) if rest.CheckBadRequestError(w, err) { return @@ -379,6 +393,8 @@ func queryVotesOnProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { // HTTP request handler to query list of governance proposals func queryProposalsWithParameterFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + _, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0) if rest.CheckBadRequestError(w, err) { return @@ -436,6 +452,8 @@ func queryProposalsWithParameterFn(clientCtx client.Context) http.HandlerFunc { // todo: Split this functionality into helper functions to remove the above func queryTallyOnProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) strProposalID := vars[RestProposalID] diff --git a/x/gov/client/rest/tx.go b/x/gov/client/rest/tx.go index 284c67148170..5e60de04d43f 100644 --- a/x/gov/client/rest/tx.go +++ b/x/gov/client/rest/tx.go @@ -26,6 +26,8 @@ func registerTxHandlers(clientCtx client.Context, r *mux.Router, phs []ProposalR func newPostProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var req PostProposalReq if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return @@ -53,6 +55,8 @@ func newPostProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { func newDepositHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -88,6 +92,8 @@ func newDepositHandlerFn(clientCtx client.Context) http.HandlerFunc { func newVoteHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) strProposalID := vars[RestProposalID] diff --git a/x/mint/client/rest/query.go b/x/mint/client/rest/query.go index 1dccd194c1ad..1a87a4a3289a 100644 --- a/x/mint/client/rest/query.go +++ b/x/mint/client/rest/query.go @@ -30,6 +30,8 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) { func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParameters) clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) @@ -49,6 +51,8 @@ func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc { func queryInflationHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryInflation) clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) @@ -68,6 +72,8 @@ func queryInflationHandlerFn(clientCtx client.Context) http.HandlerFunc { func queryAnnualProvisionsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAnnualProvisions) clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) diff --git a/x/params/client/rest/rest.go b/x/params/client/rest/rest.go index 70d90236e05f..7c9ae014f214 100644 --- a/x/params/client/rest/rest.go +++ b/x/params/client/rest/rest.go @@ -23,6 +23,8 @@ func ProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler { func postProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var req paramscutils.ParamChangeProposalReq if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return diff --git a/x/slashing/client/rest/query.go b/x/slashing/client/rest/query.go index 36eb8cc24a68..d22d3a807254 100644 --- a/x/slashing/client/rest/query.go +++ b/x/slashing/client/rest/query.go @@ -32,6 +32,8 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) { // http request handler to query signing info func signingInfoHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, vars["validatorPubKey"]) if rest.CheckBadRequestError(w, err) { @@ -64,6 +66,8 @@ func signingInfoHandlerFn(clientCtx client.Context) http.HandlerFunc { // http request handler to query signing info func signingInfoHandlerListFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + _, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0) if rest.CheckBadRequestError(w, err) { return @@ -93,6 +97,8 @@ func signingInfoHandlerListFn(clientCtx client.Context) http.HandlerFunc { func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) if !ok { return diff --git a/x/slashing/client/rest/tx.go b/x/slashing/client/rest/tx.go index eaac614fa1c4..13c1bf2930b0 100644 --- a/x/slashing/client/rest/tx.go +++ b/x/slashing/client/rest/tx.go @@ -26,6 +26,8 @@ type UnjailReq struct { // transaction. func NewUnjailRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) bech32Validator := vars["validatorAddr"] diff --git a/x/staking/client/rest/query.go b/x/staking/client/rest/query.go index cbe0813c32e3..14caf8e3f9f3 100644 --- a/x/staking/client/rest/query.go +++ b/x/staking/client/rest/query.go @@ -119,6 +119,8 @@ func delegatorUnbondingDelegationsHandlerFn(cliCtx client.Context) http.HandlerF // HTTP request handler to query all staking txs (msgs) from a delegator func delegatorTxsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var typesQuerySlice []string vars := mux.Vars(r) @@ -196,6 +198,8 @@ func unbondingDelegationHandlerFn(cliCtx client.Context) http.HandlerFunc { // HTTP request handler to query redelegations func redelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var params types.QueryRedelegationParams clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) @@ -267,6 +271,8 @@ func delegatorValidatorHandlerFn(cliCtx client.Context) http.HandlerFunc { // HTTP request handler to query list of validators func validatorsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + _, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0) if rest.CheckBadRequestError(w, err) { return @@ -319,6 +325,8 @@ func validatorUnbondingDelegationsHandlerFn(cliCtx client.Context) http.HandlerF // HTTP request handler to query historical info at a given height func historicalInfoHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) heightStr := vars["height"] @@ -348,6 +356,8 @@ func historicalInfoHandlerFn(clientCtx client.Context) http.HandlerFunc { // HTTP request handler to query the pool information func poolHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) if !ok { return @@ -366,6 +376,8 @@ func poolHandlerFn(clientCtx client.Context) http.HandlerFunc { // HTTP request handler to query the staking params values func paramsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) if !ok { return diff --git a/x/staking/client/rest/tx.go b/x/staking/client/rest/tx.go index 26e859c41a0d..b584b85e119a 100644 --- a/x/staking/client/rest/tx.go +++ b/x/staking/client/rest/tx.go @@ -57,6 +57,8 @@ type ( func newPostDelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var req DelegateRequest if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return @@ -88,6 +90,8 @@ func newPostDelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { func newPostRedelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var req RedelegateRequest if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return @@ -119,6 +123,8 @@ func newPostRedelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { func newPostUnbondingDelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var req UndelegateRequest if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return diff --git a/x/staking/client/rest/utils.go b/x/staking/client/rest/utils.go index 2b8a1c4dcfc1..b524047685b9 100644 --- a/x/staking/client/rest/utils.go +++ b/x/staking/client/rest/utils.go @@ -38,6 +38,8 @@ func queryTxs(clientCtx client.Context, action string, delegatorAddr string) (*s func queryBonds(clientCtx client.Context, endpoint string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) bech32delegator := vars["delegatorAddr"] bech32validator := vars["validatorAddr"] @@ -76,6 +78,8 @@ func queryBonds(clientCtx client.Context, endpoint string) http.HandlerFunc { func queryDelegator(clientCtx client.Context, endpoint string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) bech32delegator := vars["delegatorAddr"] @@ -108,6 +112,8 @@ func queryDelegator(clientCtx client.Context, endpoint string) http.HandlerFunc func queryValidator(clientCtx client.Context, endpoint string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + vars := mux.Vars(r) bech32validatorAddr := vars["validatorAddr"] diff --git a/x/upgrade/client/rest/query.go b/x/upgrade/client/rest/query.go index 946430634eff..57a40ce5e663 100644 --- a/x/upgrade/client/rest/query.go +++ b/x/upgrade/client/rest/query.go @@ -23,6 +23,8 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) { func getCurrentPlanHandler(clientCtx client.Context) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, request *http.Request) { + client.AddDeprecationHeaders(w) + // ignore height for now res, _, err := clientCtx.Query(fmt.Sprintf("custom/%s/%s", types.QuerierKey, types.QueryCurrent)) if rest.CheckInternalServerError(w, err) { @@ -45,6 +47,8 @@ func getCurrentPlanHandler(clientCtx client.Context) func(http.ResponseWriter, * func getDonePlanHandler(clientCtx client.Context) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + name := mux.Vars(r)["name"] params := types.QueryAppliedPlanRequest{Name: name} diff --git a/x/upgrade/client/rest/tx.go b/x/upgrade/client/rest/tx.go index 51bdb8f9235a..c7bf94ccd013 100644 --- a/x/upgrade/client/rest/tx.go +++ b/x/upgrade/client/rest/tx.go @@ -60,6 +60,8 @@ func ProposalCancelRESTHandler(clientCtx client.Context) govrest.ProposalRESTHan func newPostPlanHandler(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var req PlanRequest if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { @@ -100,6 +102,8 @@ func newPostPlanHandler(clientCtx client.Context) http.HandlerFunc { func newCancelPlanHandler(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var req CancelRequest if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { From f2e4a8a03b46d5230b7e1a774d2212c05bd517a6 Mon Sep 17 00:00:00 2001 From: Cory Levinson Date: Mon, 26 Oct 2020 18:11:27 -0700 Subject: [PATCH 2/9] add deprecation headers for missing tx routes --- x/auth/client/rest/broadcast.go | 2 ++ x/auth/client/rest/decode.go | 2 ++ x/auth/client/rest/encode.go | 2 ++ 3 files changed, 6 insertions(+) diff --git a/x/auth/client/rest/broadcast.go b/x/auth/client/rest/broadcast.go index e0020515d802..4f6e40f4813f 100644 --- a/x/auth/client/rest/broadcast.go +++ b/x/auth/client/rest/broadcast.go @@ -22,6 +22,8 @@ type BroadcastReq struct { // broadcasted via a sync|async|block mechanism. func BroadcastTxRequest(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var req BroadcastReq body, err := ioutil.ReadAll(r.Body) diff --git a/x/auth/client/rest/decode.go b/x/auth/client/rest/decode.go index ca72487a80a8..dea90f062bd4 100644 --- a/x/auth/client/rest/decode.go +++ b/x/auth/client/rest/decode.go @@ -29,6 +29,8 @@ type ( // and responds with a json-formatted transaction. func DecodeTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var req DecodeReq body, err := ioutil.ReadAll(r.Body) diff --git a/x/auth/client/rest/encode.go b/x/auth/client/rest/encode.go index 1fbc3b94f430..688e0b599625 100644 --- a/x/auth/client/rest/encode.go +++ b/x/auth/client/rest/encode.go @@ -22,6 +22,8 @@ type EncodeResp struct { // and responds with base64-encoded bytes. func EncodeTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + client.AddDeprecationHeaders(w) + var req legacytx.StdTx body, err := ioutil.ReadAll(r.Body) From 17c4cf9ed08cc5f848111823ef9596d35633a603 Mon Sep 17 00:00:00 2001 From: Cory Levinson Date: Mon, 26 Oct 2020 19:51:20 -0700 Subject: [PATCH 3/9] rm handler-level deprecation headers --- client/legacy_rest.go | 9 --------- x/auth/client/rest/broadcast.go | 2 -- x/auth/client/rest/decode.go | 2 -- x/auth/client/rest/encode.go | 2 -- x/auth/client/rest/query.go | 8 -------- x/auth/client/rest/rest.go | 3 ++- x/bank/client/rest/query.go | 5 ----- x/bank/client/rest/tx.go | 2 -- x/distribution/client/rest/query.go | 6 ------ x/distribution/client/rest/rest.go | 2 -- x/distribution/client/rest/tx.go | 10 ---------- x/evidence/client/rest/query.go | 4 ---- x/gov/client/rest/query.go | 18 ------------------ x/gov/client/rest/tx.go | 6 ------ x/mint/client/rest/query.go | 6 ------ x/params/client/rest/rest.go | 2 -- x/slashing/client/rest/query.go | 6 ------ x/slashing/client/rest/tx.go | 2 -- x/staking/client/rest/query.go | 12 ------------ x/staking/client/rest/tx.go | 6 ------ x/staking/client/rest/utils.go | 6 ------ x/upgrade/client/rest/query.go | 4 ---- x/upgrade/client/rest/tx.go | 4 ---- 23 files changed, 2 insertions(+), 125 deletions(-) delete mode 100644 client/legacy_rest.go diff --git a/client/legacy_rest.go b/client/legacy_rest.go deleted file mode 100644 index c51bc3bad09d..000000000000 --- a/client/legacy_rest.go +++ /dev/null @@ -1,9 +0,0 @@ -package client - -import "net/http" - -func AddDeprecationHeaders(rw http.ResponseWriter) http.ResponseWriter { - rw.Header().Set("Deprecation", "true") - rw.Header().Set("Link", "; rel=\"deprecation\"") - return rw -} diff --git a/x/auth/client/rest/broadcast.go b/x/auth/client/rest/broadcast.go index 4f6e40f4813f..e0020515d802 100644 --- a/x/auth/client/rest/broadcast.go +++ b/x/auth/client/rest/broadcast.go @@ -22,8 +22,6 @@ type BroadcastReq struct { // broadcasted via a sync|async|block mechanism. func BroadcastTxRequest(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var req BroadcastReq body, err := ioutil.ReadAll(r.Body) diff --git a/x/auth/client/rest/decode.go b/x/auth/client/rest/decode.go index dea90f062bd4..ca72487a80a8 100644 --- a/x/auth/client/rest/decode.go +++ b/x/auth/client/rest/decode.go @@ -29,8 +29,6 @@ type ( // and responds with a json-formatted transaction. func DecodeTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var req DecodeReq body, err := ioutil.ReadAll(r.Body) diff --git a/x/auth/client/rest/encode.go b/x/auth/client/rest/encode.go index 688e0b599625..1fbc3b94f430 100644 --- a/x/auth/client/rest/encode.go +++ b/x/auth/client/rest/encode.go @@ -22,8 +22,6 @@ type EncodeResp struct { // and responds with base64-encoded bytes. func EncodeTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var req legacytx.StdTx body, err := ioutil.ReadAll(r.Body) diff --git a/x/auth/client/rest/query.go b/x/auth/client/rest/query.go index 8da10078f76e..c40fc5530d77 100644 --- a/x/auth/client/rest/query.go +++ b/x/auth/client/rest/query.go @@ -19,8 +19,6 @@ import ( // query accountREST Handler func QueryAccountRequestHandlerFn(storeName string, clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) bech32addr := vars["address"] @@ -60,8 +58,6 @@ func QueryAccountRequestHandlerFn(storeName string, clientCtx client.Context) ht // otherwise the transactions are searched for by events. func QueryTxsRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - err := r.ParseForm() if err != nil { rest.WriteErrorResponse( @@ -114,8 +110,6 @@ func QueryTxsRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { // by hash in a committed block. func QueryTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) hashHexStr := vars["hash"] @@ -152,8 +146,6 @@ func QueryTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { func queryParamsHandler(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) if !ok { return diff --git a/x/auth/client/rest/rest.go b/x/auth/client/rest/rest.go index 213b99c8102d..d3106edca229 100644 --- a/x/auth/client/rest/rest.go +++ b/x/auth/client/rest/rest.go @@ -1,8 +1,9 @@ package rest import ( - "github.com/cosmos/cosmos-sdk/client" "github.com/gorilla/mux" + + "github.com/cosmos/cosmos-sdk/client" ) // REST query and parameter values diff --git a/x/bank/client/rest/query.go b/x/bank/client/rest/query.go index 1c2f63d6a44b..7c88c790f83c 100644 --- a/x/bank/client/rest/query.go +++ b/x/bank/client/rest/query.go @@ -16,7 +16,6 @@ import ( // account balances or a specific balance by denomination. func QueryBalancesRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) w.Header().Set("Content-Type", "application/json") vars := mux.Vars(r) @@ -64,8 +63,6 @@ func QueryBalancesRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { // HTTP request handler to query the total supply of coins func totalSupplyHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - _, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0) if rest.CheckBadRequestError(w, err) { return @@ -97,8 +94,6 @@ func totalSupplyHandlerFn(clientCtx client.Context) http.HandlerFunc { // HTTP request handler to query the supply of a single denom func supplyOfHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - denom := mux.Vars(r)["denom"] clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) if !ok { diff --git a/x/bank/client/rest/tx.go b/x/bank/client/rest/tx.go index 1bbdbf0cd04e..e630710dff22 100644 --- a/x/bank/client/rest/tx.go +++ b/x/bank/client/rest/tx.go @@ -22,8 +22,6 @@ type SendReq struct { // transaction. func NewSendRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) bech32Addr := vars["address"] diff --git a/x/distribution/client/rest/query.go b/x/distribution/client/rest/query.go index a49cac5a5339..0fb923afc94d 100644 --- a/x/distribution/client/rest/query.go +++ b/x/distribution/client/rest/query.go @@ -68,8 +68,6 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) { // HTTP request handler to query the total rewards balance from all delegations func delegatorRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) if !ok { return @@ -101,8 +99,6 @@ func delegatorRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { // HTTP request handler to query a delegation rewards func delegationRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) if !ok { return @@ -125,8 +121,6 @@ func delegationRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { // HTTP request handler to query a delegation rewards func delegatorWithdrawalAddrHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - delegatorAddr, ok := checkDelegatorAddressVar(w, r) if !ok { return diff --git a/x/distribution/client/rest/rest.go b/x/distribution/client/rest/rest.go index e2003ed015b7..0269e9261188 100644 --- a/x/distribution/client/rest/rest.go +++ b/x/distribution/client/rest/rest.go @@ -29,8 +29,6 @@ func ProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler { func postProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var req CommunityPoolSpendProposalReq if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return diff --git a/x/distribution/client/rest/tx.go b/x/distribution/client/rest/tx.go index 8d8ced41d505..675be4af1abc 100644 --- a/x/distribution/client/rest/tx.go +++ b/x/distribution/client/rest/tx.go @@ -63,8 +63,6 @@ func registerTxHandlers(clientCtx client.Context, r *mux.Router) { func newWithdrawDelegatorRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var req withdrawRewardsReq if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return @@ -92,8 +90,6 @@ func newWithdrawDelegatorRewardsHandlerFn(clientCtx client.Context) http.Handler func newWithdrawDelegationRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var req withdrawRewardsReq if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return @@ -126,8 +122,6 @@ func newWithdrawDelegationRewardsHandlerFn(clientCtx client.Context) http.Handle func newSetDelegatorWithdrawalAddrHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var req setWithdrawalAddrReq if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return @@ -155,8 +149,6 @@ func newSetDelegatorWithdrawalAddrHandlerFn(clientCtx client.Context) http.Handl func newWithdrawValidatorRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var req withdrawRewardsReq if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return @@ -185,8 +177,6 @@ func newWithdrawValidatorRewardsHandlerFn(clientCtx client.Context) http.Handler func newFundCommunityPoolHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var req fundCommunityPoolReq if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return diff --git a/x/evidence/client/rest/query.go b/x/evidence/client/rest/query.go index 94c4aecd6249..21ae8b7bb306 100644 --- a/x/evidence/client/rest/query.go +++ b/x/evidence/client/rest/query.go @@ -27,8 +27,6 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) { func queryEvidenceHandler(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) evidenceHash := vars[RestParamEvidenceHash] @@ -68,8 +66,6 @@ func queryEvidenceHandler(clientCtx client.Context) http.HandlerFunc { func queryAllEvidenceHandler(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - _, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0) if rest.CheckBadRequestError(w, err) { return diff --git a/x/gov/client/rest/query.go b/x/gov/client/rest/query.go index d198f4b5a947..ffdbd8bc0290 100644 --- a/x/gov/client/rest/query.go +++ b/x/gov/client/rest/query.go @@ -28,8 +28,6 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) { func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) paramType := vars[RestParamsType] @@ -50,8 +48,6 @@ func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc { func queryProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -90,8 +86,6 @@ func queryProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { func queryDepositsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -141,8 +135,6 @@ func queryDepositsHandlerFn(clientCtx client.Context) http.HandlerFunc { func queryProposerHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -167,8 +159,6 @@ func queryProposerHandlerFn(clientCtx client.Context) http.HandlerFunc { func queryDepositHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) strProposalID := vars[RestProposalID] bechDepositorAddr := vars[RestDepositor] @@ -245,8 +235,6 @@ func queryDepositHandlerFn(clientCtx client.Context) http.HandlerFunc { func queryVoteHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) strProposalID := vars[RestProposalID] bechVoterAddr := vars[RestVoter] @@ -325,8 +313,6 @@ func queryVoteHandlerFn(clientCtx client.Context) http.HandlerFunc { // todo: Split this functionality into helper functions to remove the above func queryVotesOnProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - _, page, limit, err := rest.ParseHTTPArgs(r) if rest.CheckBadRequestError(w, err) { return @@ -393,8 +379,6 @@ func queryVotesOnProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { // HTTP request handler to query list of governance proposals func queryProposalsWithParameterFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - _, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0) if rest.CheckBadRequestError(w, err) { return @@ -452,8 +436,6 @@ func queryProposalsWithParameterFn(clientCtx client.Context) http.HandlerFunc { // todo: Split this functionality into helper functions to remove the above func queryTallyOnProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) strProposalID := vars[RestProposalID] diff --git a/x/gov/client/rest/tx.go b/x/gov/client/rest/tx.go index 5e60de04d43f..284c67148170 100644 --- a/x/gov/client/rest/tx.go +++ b/x/gov/client/rest/tx.go @@ -26,8 +26,6 @@ func registerTxHandlers(clientCtx client.Context, r *mux.Router, phs []ProposalR func newPostProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var req PostProposalReq if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return @@ -55,8 +53,6 @@ func newPostProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { func newDepositHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -92,8 +88,6 @@ func newDepositHandlerFn(clientCtx client.Context) http.HandlerFunc { func newVoteHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) strProposalID := vars[RestProposalID] diff --git a/x/mint/client/rest/query.go b/x/mint/client/rest/query.go index 1a87a4a3289a..1dccd194c1ad 100644 --- a/x/mint/client/rest/query.go +++ b/x/mint/client/rest/query.go @@ -30,8 +30,6 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) { func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParameters) clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) @@ -51,8 +49,6 @@ func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc { func queryInflationHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryInflation) clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) @@ -72,8 +68,6 @@ func queryInflationHandlerFn(clientCtx client.Context) http.HandlerFunc { func queryAnnualProvisionsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAnnualProvisions) clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) diff --git a/x/params/client/rest/rest.go b/x/params/client/rest/rest.go index 7c9ae014f214..70d90236e05f 100644 --- a/x/params/client/rest/rest.go +++ b/x/params/client/rest/rest.go @@ -23,8 +23,6 @@ func ProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler { func postProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var req paramscutils.ParamChangeProposalReq if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return diff --git a/x/slashing/client/rest/query.go b/x/slashing/client/rest/query.go index d22d3a807254..36eb8cc24a68 100644 --- a/x/slashing/client/rest/query.go +++ b/x/slashing/client/rest/query.go @@ -32,8 +32,6 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) { // http request handler to query signing info func signingInfoHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, vars["validatorPubKey"]) if rest.CheckBadRequestError(w, err) { @@ -66,8 +64,6 @@ func signingInfoHandlerFn(clientCtx client.Context) http.HandlerFunc { // http request handler to query signing info func signingInfoHandlerListFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - _, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0) if rest.CheckBadRequestError(w, err) { return @@ -97,8 +93,6 @@ func signingInfoHandlerListFn(clientCtx client.Context) http.HandlerFunc { func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) if !ok { return diff --git a/x/slashing/client/rest/tx.go b/x/slashing/client/rest/tx.go index 13c1bf2930b0..eaac614fa1c4 100644 --- a/x/slashing/client/rest/tx.go +++ b/x/slashing/client/rest/tx.go @@ -26,8 +26,6 @@ type UnjailReq struct { // transaction. func NewUnjailRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) bech32Validator := vars["validatorAddr"] diff --git a/x/staking/client/rest/query.go b/x/staking/client/rest/query.go index 14caf8e3f9f3..cbe0813c32e3 100644 --- a/x/staking/client/rest/query.go +++ b/x/staking/client/rest/query.go @@ -119,8 +119,6 @@ func delegatorUnbondingDelegationsHandlerFn(cliCtx client.Context) http.HandlerF // HTTP request handler to query all staking txs (msgs) from a delegator func delegatorTxsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var typesQuerySlice []string vars := mux.Vars(r) @@ -198,8 +196,6 @@ func unbondingDelegationHandlerFn(cliCtx client.Context) http.HandlerFunc { // HTTP request handler to query redelegations func redelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var params types.QueryRedelegationParams clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) @@ -271,8 +267,6 @@ func delegatorValidatorHandlerFn(cliCtx client.Context) http.HandlerFunc { // HTTP request handler to query list of validators func validatorsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - _, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0) if rest.CheckBadRequestError(w, err) { return @@ -325,8 +319,6 @@ func validatorUnbondingDelegationsHandlerFn(cliCtx client.Context) http.HandlerF // HTTP request handler to query historical info at a given height func historicalInfoHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) heightStr := vars["height"] @@ -356,8 +348,6 @@ func historicalInfoHandlerFn(clientCtx client.Context) http.HandlerFunc { // HTTP request handler to query the pool information func poolHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) if !ok { return @@ -376,8 +366,6 @@ func poolHandlerFn(clientCtx client.Context) http.HandlerFunc { // HTTP request handler to query the staking params values func paramsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r) if !ok { return diff --git a/x/staking/client/rest/tx.go b/x/staking/client/rest/tx.go index b584b85e119a..26e859c41a0d 100644 --- a/x/staking/client/rest/tx.go +++ b/x/staking/client/rest/tx.go @@ -57,8 +57,6 @@ type ( func newPostDelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var req DelegateRequest if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return @@ -90,8 +88,6 @@ func newPostDelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { func newPostRedelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var req RedelegateRequest if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return @@ -123,8 +119,6 @@ func newPostRedelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { func newPostUnbondingDelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var req UndelegateRequest if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { return diff --git a/x/staking/client/rest/utils.go b/x/staking/client/rest/utils.go index b524047685b9..2b8a1c4dcfc1 100644 --- a/x/staking/client/rest/utils.go +++ b/x/staking/client/rest/utils.go @@ -38,8 +38,6 @@ func queryTxs(clientCtx client.Context, action string, delegatorAddr string) (*s func queryBonds(clientCtx client.Context, endpoint string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) bech32delegator := vars["delegatorAddr"] bech32validator := vars["validatorAddr"] @@ -78,8 +76,6 @@ func queryBonds(clientCtx client.Context, endpoint string) http.HandlerFunc { func queryDelegator(clientCtx client.Context, endpoint string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) bech32delegator := vars["delegatorAddr"] @@ -112,8 +108,6 @@ func queryDelegator(clientCtx client.Context, endpoint string) http.HandlerFunc func queryValidator(clientCtx client.Context, endpoint string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - vars := mux.Vars(r) bech32validatorAddr := vars["validatorAddr"] diff --git a/x/upgrade/client/rest/query.go b/x/upgrade/client/rest/query.go index 57a40ce5e663..946430634eff 100644 --- a/x/upgrade/client/rest/query.go +++ b/x/upgrade/client/rest/query.go @@ -23,8 +23,6 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) { func getCurrentPlanHandler(clientCtx client.Context) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, request *http.Request) { - client.AddDeprecationHeaders(w) - // ignore height for now res, _, err := clientCtx.Query(fmt.Sprintf("custom/%s/%s", types.QuerierKey, types.QueryCurrent)) if rest.CheckInternalServerError(w, err) { @@ -47,8 +45,6 @@ func getCurrentPlanHandler(clientCtx client.Context) func(http.ResponseWriter, * func getDonePlanHandler(clientCtx client.Context) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - name := mux.Vars(r)["name"] params := types.QueryAppliedPlanRequest{Name: name} diff --git a/x/upgrade/client/rest/tx.go b/x/upgrade/client/rest/tx.go index c7bf94ccd013..51bdb8f9235a 100644 --- a/x/upgrade/client/rest/tx.go +++ b/x/upgrade/client/rest/tx.go @@ -60,8 +60,6 @@ func ProposalCancelRESTHandler(clientCtx client.Context) govrest.ProposalRESTHan func newPostPlanHandler(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var req PlanRequest if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { @@ -102,8 +100,6 @@ func newPostPlanHandler(clientCtx client.Context) http.HandlerFunc { func newCancelPlanHandler(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - client.AddDeprecationHeaders(w) - var req CancelRequest if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) { From abd61705ec83db06de0959afae1a97b2f988f361 Mon Sep 17 00:00:00 2001 From: Cory Levinson Date: Mon, 26 Oct 2020 20:02:23 -0700 Subject: [PATCH 4/9] switch to middleware Route.Use method for setting deprecation Headers --- types/module/module.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/types/module/module.go b/types/module/module.go index ec9c1c77b5d3..f5f0a96078f2 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -30,6 +30,7 @@ package module import ( "encoding/json" + "net/http" "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -108,8 +109,17 @@ func (bm BasicManager) ValidateGenesis(cdc codec.JSONMarshaler, txEncCfg client. return nil } +func addDeprecationHeaders(h http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Deprecation", "true") + w.Header().Set("Link", "; rel=\"deprecation\"") + h.ServeHTTP(w, r) + }) +} + // RegisterRESTRoutes registers all module rest routes func (bm BasicManager) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { + rtr.Use(addDeprecationHeaders) for _, b := range bm { b.RegisterRESTRoutes(clientCtx, rtr) } From b7e828d5e12313f353e2d278e65bb6c8465d6d1a Mon Sep 17 00:00:00 2001 From: Cory Levinson Date: Tue, 27 Oct 2020 15:43:12 -0700 Subject: [PATCH 5/9] set deprecation headers using subrouter --- client/rest/rest.go | 25 +++++++++++++++++++++++++ types/module/module.go | 14 ++------------ x/auth/client/rest/rest.go | 4 +++- 3 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 client/rest/rest.go diff --git a/client/rest/rest.go b/client/rest/rest.go new file mode 100644 index 000000000000..d543c8241d03 --- /dev/null +++ b/client/rest/rest.go @@ -0,0 +1,25 @@ +package rest + +import ( + "github.com/gorilla/mux" + "net/http" +) + +// addHTTPDeprecationHeaders is a mux middleware function for adding HTTP +// Deprecation headers to a http handler +func addHTTPDeprecationHeaders(h http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Deprecation", "true") + w.Header().Set("Link", "; rel=\"deprecation\"") + h.ServeHTTP(w, r) + }) +} + +// WithHTTPDeprecationHeaders returns a new *mux.Router, identical to its input +// but with the addition of HTTP Deprecation headers. This is used to mark legacy +// amino REST endpoints as deprecated in the REST API. +func WithHTTPDeprecationHeaders(r *mux.Router) *mux.Router { + subRouter := r.NewRoute().Subrouter() + subRouter.Use(addHTTPDeprecationHeaders) + return subRouter +} diff --git a/types/module/module.go b/types/module/module.go index f5f0a96078f2..8a306ea23ce3 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -30,8 +30,7 @@ package module import ( "encoding/json" - "net/http" - + "github.com/cosmos/cosmos-sdk/client/rest" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/gorilla/mux" @@ -109,19 +108,10 @@ func (bm BasicManager) ValidateGenesis(cdc codec.JSONMarshaler, txEncCfg client. return nil } -func addDeprecationHeaders(h http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Deprecation", "true") - w.Header().Set("Link", "; rel=\"deprecation\"") - h.ServeHTTP(w, r) - }) -} - // RegisterRESTRoutes registers all module rest routes func (bm BasicManager) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { - rtr.Use(addDeprecationHeaders) for _, b := range bm { - b.RegisterRESTRoutes(clientCtx, rtr) + b.RegisterRESTRoutes(clientCtx, rest.WithHTTPDeprecationHeaders(rtr)) } } diff --git a/x/auth/client/rest/rest.go b/x/auth/client/rest/rest.go index d3106edca229..e80ede14476f 100644 --- a/x/auth/client/rest/rest.go +++ b/x/auth/client/rest/rest.go @@ -1,6 +1,7 @@ package rest import ( + "github.com/cosmos/cosmos-sdk/client/rest" "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" @@ -24,7 +25,8 @@ func RegisterRoutes(clientCtx client.Context, r *mux.Router, storeName string) { } // RegisterTxRoutes registers all transaction routes on the provided router. -func RegisterTxRoutes(clientCtx client.Context, r *mux.Router) { +func RegisterTxRoutes(clientCtx client.Context, rtr *mux.Router) { + r := rest.WithHTTPDeprecationHeaders(rtr) r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(clientCtx)).Methods("GET") r.HandleFunc("/txs", QueryTxsRequestHandlerFn(clientCtx)).Methods("GET") r.HandleFunc("/txs", BroadcastTxRequest(clientCtx)).Methods("POST") From abccbb246ecc9c47c492e78f897291fbd742641d Mon Sep 17 00:00:00 2001 From: Cory Levinson Date: Tue, 27 Oct 2020 17:16:23 -0700 Subject: [PATCH 6/9] cleanup gofmt --- client/rest/rest.go | 3 ++- types/module/module.go | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/client/rest/rest.go b/client/rest/rest.go index d543c8241d03..340db11b4506 100644 --- a/client/rest/rest.go +++ b/client/rest/rest.go @@ -1,8 +1,9 @@ package rest import ( - "github.com/gorilla/mux" "net/http" + + "github.com/gorilla/mux" ) // addHTTPDeprecationHeaders is a mux middleware function for adding HTTP diff --git a/types/module/module.go b/types/module/module.go index 8a306ea23ce3..db11c3e15977 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -30,14 +30,14 @@ package module import ( "encoding/json" - "github.com/cosmos/cosmos-sdk/client/rest" - "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/rest" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -110,8 +110,9 @@ func (bm BasicManager) ValidateGenesis(cdc codec.JSONMarshaler, txEncCfg client. // RegisterRESTRoutes registers all module rest routes func (bm BasicManager) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { + r := rest.WithHTTPDeprecationHeaders(rtr) for _, b := range bm { - b.RegisterRESTRoutes(clientCtx, rest.WithHTTPDeprecationHeaders(rtr)) + b.RegisterRESTRoutes(clientCtx, r) } } From 7d509fda7f2ff5ea49a199939bfba36857b78e21 Mon Sep 17 00:00:00 2001 From: Cory Levinson Date: Wed, 28 Oct 2020 13:01:57 -0700 Subject: [PATCH 7/9] goimports --- x/auth/client/rest/rest.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/client/rest/rest.go b/x/auth/client/rest/rest.go index e80ede14476f..0fe0ed494349 100644 --- a/x/auth/client/rest/rest.go +++ b/x/auth/client/rest/rest.go @@ -1,10 +1,10 @@ package rest import ( - "github.com/cosmos/cosmos-sdk/client/rest" "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/rest" ) // REST query and parameter values From 3e39d451e2bcb58ea5355b1d71cf0754a7b5b7df Mon Sep 17 00:00:00 2001 From: Cory Date: Wed, 28 Oct 2020 13:38:19 -0700 Subject: [PATCH 8/9] Update client/rest/rest.go --- client/rest/rest.go | 1 + 1 file changed, 1 insertion(+) diff --git a/client/rest/rest.go b/client/rest/rest.go index 340db11b4506..9a0f901840a6 100644 --- a/client/rest/rest.go +++ b/client/rest/rest.go @@ -12,6 +12,7 @@ func addHTTPDeprecationHeaders(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Deprecation", "true") w.Header().Set("Link", "; rel=\"deprecation\"") + w.Header().Set("Warning", "199 - \"this endpoint is deprecated and may not work as before, see deprecation link for more info\"") h.ServeHTTP(w, r) }) } From abe10d8989c47f990c66f32df0c18f21ba5e44d9 Mon Sep 17 00:00:00 2001 From: Cory Levinson Date: Wed, 28 Oct 2020 20:29:37 -0700 Subject: [PATCH 9/9] update deprecation headers to be set on each module individually --- types/module/module.go | 4 +--- x/auth/client/rest/rest.go | 3 ++- x/bank/client/rest/rest.go | 4 +++- x/distribution/client/rest/rest.go | 5 ++++- x/evidence/client/rest/rest.go | 5 ++++- x/gov/client/rest/rest.go | 4 +++- x/mint/client/rest/rest.go | 4 +++- x/slashing/client/rest/rest.go | 5 ++++- x/staking/client/rest/rest.go | 4 +++- x/upgrade/client/rest/rest.go | 4 +++- 10 files changed, 30 insertions(+), 12 deletions(-) diff --git a/types/module/module.go b/types/module/module.go index db11c3e15977..b2a284d2c9b8 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -37,7 +37,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/rest" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -110,9 +109,8 @@ func (bm BasicManager) ValidateGenesis(cdc codec.JSONMarshaler, txEncCfg client. // RegisterRESTRoutes registers all module rest routes func (bm BasicManager) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { - r := rest.WithHTTPDeprecationHeaders(rtr) for _, b := range bm { - b.RegisterRESTRoutes(clientCtx, r) + b.RegisterRESTRoutes(clientCtx, rtr) } } diff --git a/x/auth/client/rest/rest.go b/x/auth/client/rest/rest.go index 0fe0ed494349..77f8f4896465 100644 --- a/x/auth/client/rest/rest.go +++ b/x/auth/client/rest/rest.go @@ -13,7 +13,8 @@ const ( ) // RegisterRoutes registers the auth module REST routes. -func RegisterRoutes(clientCtx client.Context, r *mux.Router, storeName string) { +func RegisterRoutes(clientCtx client.Context, rtr *mux.Router, storeName string) { + r := rest.WithHTTPDeprecationHeaders(rtr) r.HandleFunc( "/auth/accounts/{address}", QueryAccountRequestHandlerFn(storeName, clientCtx), ).Methods(MethodGet) diff --git a/x/bank/client/rest/rest.go b/x/bank/client/rest/rest.go index e70a946d2601..4325386d445e 100644 --- a/x/bank/client/rest/rest.go +++ b/x/bank/client/rest/rest.go @@ -1,6 +1,7 @@ package rest import ( + "github.com/cosmos/cosmos-sdk/client/rest" "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" @@ -8,7 +9,8 @@ import ( // RegisterHandlers registers all x/bank transaction and query HTTP REST handlers // on the provided mux router. -func RegisterHandlers(clientCtx client.Context, r *mux.Router) { +func RegisterHandlers(clientCtx client.Context, rtr *mux.Router) { + r := rest.WithHTTPDeprecationHeaders(rtr) r.HandleFunc("/bank/accounts/{address}/transfers", NewSendRequestHandlerFn(clientCtx)).Methods("POST") r.HandleFunc("/bank/balances/{address}", QueryBalancesRequestHandlerFn(clientCtx)).Methods("GET") r.HandleFunc("/bank/total", totalSupplyHandlerFn(clientCtx)).Methods("GET") diff --git a/x/distribution/client/rest/rest.go b/x/distribution/client/rest/rest.go index 0269e9261188..3fdcef89e1cc 100644 --- a/x/distribution/client/rest/rest.go +++ b/x/distribution/client/rest/rest.go @@ -6,6 +6,7 @@ import ( "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" + clientrest "github.com/cosmos/cosmos-sdk/client/rest" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/types/rest" "github.com/cosmos/cosmos-sdk/x/distribution/types" @@ -13,7 +14,9 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) -func RegisterHandlers(clientCtx client.Context, r *mux.Router) { +func RegisterHandlers(clientCtx client.Context, rtr *mux.Router) { + r := clientrest.WithHTTPDeprecationHeaders(rtr) + registerQueryRoutes(clientCtx, r) registerTxHandlers(clientCtx, r) } diff --git a/x/evidence/client/rest/rest.go b/x/evidence/client/rest/rest.go index 89756eb58aa0..f2714cc7ba4e 100644 --- a/x/evidence/client/rest/rest.go +++ b/x/evidence/client/rest/rest.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/rest" "github.com/gorilla/mux" ) @@ -24,7 +25,9 @@ type EvidenceRESTHandler struct { // RegisterRoutes registers all Evidence submission handlers for the evidence module's // REST service handler. -func RegisterRoutes(clientCtx client.Context, r *mux.Router, handlers []EvidenceRESTHandler) { +func RegisterRoutes(clientCtx client.Context, rtr *mux.Router, handlers []EvidenceRESTHandler) { + r := rest.WithHTTPDeprecationHeaders(rtr) + registerQueryRoutes(clientCtx, r) registerTxRoutes(clientCtx, r, handlers) } diff --git a/x/gov/client/rest/rest.go b/x/gov/client/rest/rest.go index 5136e19ea1f5..f11798e96760 100644 --- a/x/gov/client/rest/rest.go +++ b/x/gov/client/rest/rest.go @@ -6,6 +6,7 @@ import ( "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" + clientrest "github.com/cosmos/cosmos-sdk/client/rest" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" ) @@ -28,7 +29,8 @@ type ProposalRESTHandler struct { Handler func(http.ResponseWriter, *http.Request) } -func RegisterHandlers(clientCtx client.Context, r *mux.Router, phs []ProposalRESTHandler) { +func RegisterHandlers(clientCtx client.Context, rtr *mux.Router, phs []ProposalRESTHandler) { + r := clientrest.WithHTTPDeprecationHeaders(rtr) registerQueryRoutes(clientCtx, r) registerTxHandlers(clientCtx, r, phs) } diff --git a/x/mint/client/rest/rest.go b/x/mint/client/rest/rest.go index a159739a0b59..2ed28d41d771 100644 --- a/x/mint/client/rest/rest.go +++ b/x/mint/client/rest/rest.go @@ -4,9 +4,11 @@ import ( "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/rest" ) // RegisterRoutes registers minting module REST handlers on the provided router. -func RegisterRoutes(clientCtx client.Context, r *mux.Router) { +func RegisterRoutes(clientCtx client.Context, rtr *mux.Router) { + r := rest.WithHTTPDeprecationHeaders(rtr) registerQueryRoutes(clientCtx, r) } diff --git a/x/slashing/client/rest/rest.go b/x/slashing/client/rest/rest.go index cdce1a34a093..21d73a5e8866 100644 --- a/x/slashing/client/rest/rest.go +++ b/x/slashing/client/rest/rest.go @@ -1,12 +1,15 @@ package rest import ( + "github.com/cosmos/cosmos-sdk/client/rest" "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" ) -func RegisterHandlers(clientCtx client.Context, r *mux.Router) { +func RegisterHandlers(clientCtx client.Context, rtr *mux.Router) { + r := rest.WithHTTPDeprecationHeaders(rtr) + registerQueryRoutes(clientCtx, r) registerTxHandlers(clientCtx, r) } diff --git a/x/staking/client/rest/rest.go b/x/staking/client/rest/rest.go index cdce1a34a093..bb4e82917c92 100644 --- a/x/staking/client/rest/rest.go +++ b/x/staking/client/rest/rest.go @@ -1,12 +1,14 @@ package rest import ( + "github.com/cosmos/cosmos-sdk/client/rest" "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" ) -func RegisterHandlers(clientCtx client.Context, r *mux.Router) { +func RegisterHandlers(clientCtx client.Context, rtr *mux.Router) { + r := rest.WithHTTPDeprecationHeaders(rtr) registerQueryRoutes(clientCtx, r) registerTxHandlers(clientCtx, r) } diff --git a/x/upgrade/client/rest/rest.go b/x/upgrade/client/rest/rest.go index cdb078e7da58..83577c0cbc21 100644 --- a/x/upgrade/client/rest/rest.go +++ b/x/upgrade/client/rest/rest.go @@ -1,13 +1,15 @@ package rest import ( + "github.com/cosmos/cosmos-sdk/client/rest" "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" ) // RegisterRoutes registers REST routes for the upgrade module under the path specified by routeName. -func RegisterRoutes(clientCtx client.Context, r *mux.Router) { +func RegisterRoutes(clientCtx client.Context, rtr *mux.Router) { + r := rest.WithHTTPDeprecationHeaders(rtr) registerQueryRoutes(clientCtx, r) registerTxHandlers(clientCtx, r) }