Skip to content

feat!: remove legacy REST #9594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
57d94c6
remove rest client from x/*
aleem1314 Jun 28, 2021
a285c72
removed RegisterRESTRoutes from x/*
aleem1314 Jun 29, 2021
59ca884
remove legacy rest wiring
aleem1314 Jun 29, 2021
81a9bbe
make mocks
aleem1314 Jun 29, 2021
307c503
refactor grpc tests
aleem1314 Jun 30, 2021
1997439
remove client/rpc REST
aleem1314 Jun 30, 2021
4fa7c43
Merge branch 'master' into aleem/7517-remove-legacy-rest
aleem1314 Jun 30, 2021
3eb5be7
move types/rest to testutil/rest
aleem1314 Jun 30, 2021
400b188
fix lint errors
aleem1314 Jun 30, 2021
405671c
fix lint errors
aleem1314 Jun 30, 2021
b778852
review changes
aleem1314 Jul 1, 2021
d28daf8
Add DefaultPage doc
aleem1314 Jul 1, 2021
4e5d4be
remove legacy swagger
aleem1314 Jul 1, 2021
2b40c22
WIP review changes
aleem1314 Jul 1, 2021
d2f1a13
fix lint errors
aleem1314 Jul 1, 2021
5e98b22
WIP integration tests refactor
aleem1314 Jul 2, 2021
4b605a2
WIP staking tests refactor
aleem1314 Jul 2, 2021
1318e84
fix tests
aleem1314 Jul 2, 2021
e366149
refactor gov module integration tests
aleem1314 Jul 2, 2021
51c595d
refactor x/bank integration tests
aleem1314 Jul 2, 2021
23e83c4
refactor staking integration tests
aleem1314 Jul 2, 2021
c075bc9
Update CHANGELOG.md
aleem1314 Jul 2, 2021
4292e7a
Merge branch 'master' into aleem/7517-remove-legacy-rest
aleem1314 Jul 2, 2021
e3c3dc3
update staking integration tests
aleem1314 Jul 3, 2021
d68dd92
fix tests
aleem1314 Jul 3, 2021
a0fd07a
Merge branch 'master' into aleem/7517-remove-legacy-rest
aleem1314 Jul 3, 2021
2431964
fix tests
aleem1314 Jul 3, 2021
c4a7a30
Update CHANGELOG.md
aleem1314 Jul 5, 2021
d2f2c03
Merge branch 'master' into aleem/7517-remove-legacy-rest
aleem1314 Jul 5, 2021
665fde3
make update-swagger-docs
aleem1314 Jul 5, 2021
fa2165f
fix imports
aleem1314 Jul 5, 2021
c3fd850
add Deprecated message
aleem1314 Jul 6, 2021
061a8c8
Merge branch 'master' into aleem/7517-remove-legacy-rest
aleem1314 Jul 6, 2021
215bf26
Add build norace flag
aleem1314 Jul 6, 2021
03e2f3d
Merge branch 'master' into aleem/7517-remove-legacy-rest
aleem1314 Jul 6, 2021
60950ca
Merge branch 'aleem/7517-remove-legacy-rest' of https://github.com/co…
aleem1314 Jul 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/grpc/tmservice/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/network"
qtypes "github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/testutil/rest"
"github.com/cosmos/cosmos-sdk/version"
)

Expand Down
33 changes: 0 additions & 33 deletions client/rest/rest.go

This file was deleted.

47 changes: 0 additions & 47 deletions client/rpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ package rpc
import (
"context"
"fmt"
"net/http"
"strconv"

"github.com/gorilla/mux"
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/types/rest"
)

// BlockCommand returns the verified block data for a given heights
Expand Down Expand Up @@ -88,47 +85,3 @@ func GetChainHeight(clientCtx client.Context) (int64, error) {
height := status.SyncInfo.LatestBlockHeight
return height, nil
}

// REST handler to get a block
func BlockRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)

height, err := strconv.ParseInt(vars["height"], 10, 64)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest,
"couldn't parse block height. Assumed format is '/block/{height}'.")
return
}

chainHeight, err := GetChainHeight(clientCtx)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, "failed to parse chain height")
return
}

if height > chainHeight {
rest.WriteErrorResponse(w, http.StatusNotFound, "requested block height is bigger then the chain length")
return
}

output, err := getBlock(clientCtx, &height)
if rest.CheckInternalServerError(w, err) {
return
}

rest.PostProcessResponseBare(w, clientCtx, output)
}
}

// REST handler to get the latest block
func LatestBlockRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
output, err := getBlock(clientCtx, nil)
if rest.CheckInternalServerError(w, err) {
return
}

rest.PostProcessResponseBare(w, clientCtx, output)
}
}
17 changes: 0 additions & 17 deletions client/rpc/routes.go

This file was deleted.

14 changes: 0 additions & 14 deletions client/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import (
"testing"

"github.com/stretchr/testify/suite"
ctypes "github.com/tendermint/tendermint/rpc/core/types"

"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/codec/legacy"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/types/rest"
)

type IntegrationTestSuite struct {
Expand Down Expand Up @@ -46,17 +43,6 @@ func (s *IntegrationTestSuite) TestStatusCommand() {
s.Require().Contains(out.String(), fmt.Sprintf("\"moniker\":\"%s\"", val0.Moniker))
}

func (s *IntegrationTestSuite) TestLatestBlocks() {
val0 := s.network.Validators[0]

res, err := rest.GetRequest(fmt.Sprintf("%s/blocks/latest", val0.APIAddress))
s.Require().NoError(err)

var result ctypes.ResultBlock
err = legacy.Cdc.UnmarshalJSON(res, &result)
s.Require().NoError(err)
}

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}
45 changes: 0 additions & 45 deletions client/rpc/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rpc

import (
"context"
"net/http"

"github.com/spf13/cobra"

Expand All @@ -14,8 +13,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/version"
)

// ValidatorInfo is info about the node's validator, same as Tendermint,
Expand Down Expand Up @@ -88,45 +85,3 @@ func getNodeStatus(clientCtx client.Context) (*ctypes.ResultStatus, error) {

return node.Status(context.Background())
}

// NodeInfoResponse defines a response type that contains node status and version
// information.
type NodeInfoResponse struct {
p2p.DefaultNodeInfo `json:"node_info"`

ApplicationVersion version.Info `json:"application_version"`
}

// REST handler for node info
func NodeInfoRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
status, err := getNodeStatus(clientCtx)
if rest.CheckInternalServerError(w, err) {
return
}

resp := NodeInfoResponse{
DefaultNodeInfo: status.NodeInfo,
ApplicationVersion: version.NewInfo(),
}

rest.PostProcessResponseBare(w, clientCtx, resp)
}
}

// SyncingResponse defines a response type that contains node syncing information.
type SyncingResponse struct {
Syncing bool `json:"syncing"`
}

// REST handler for node syncing
func NodeSyncingRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
status, err := getNodeStatus(clientCtx)
if rest.CheckInternalServerError(w, err) {
return
}

rest.PostProcessResponseBare(w, clientCtx, SyncingResponse{Syncing: status.SyncInfo.CatchingUp})
}
}
60 changes: 2 additions & 58 deletions client/rpc/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package rpc
import (
"context"
"fmt"
"net/http"
"strconv"
"strings"

"github.com/gorilla/mux"
"github.com/spf13/cobra"
tmtypes "github.com/tendermint/tendermint/types"

Expand All @@ -16,7 +14,7 @@ import (
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/types/query"
)

// TODO these next two functions feel kinda hacky based on their placement
Expand Down Expand Up @@ -60,7 +58,7 @@ func ValidatorCommand() *cobra.Command {

cmd.Flags().StringP(flags.FlagNode, "n", "tcp://localhost:26657", "Node to connect to")
cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)")
cmd.Flags().Int(flags.FlagPage, rest.DefaultPage, "Query a specific page of paginated results")
cmd.Flags().Int(flags.FlagPage, query.DefaultPage, "Query a specific page of paginated results")
cmd.Flags().Int(flags.FlagLimit, 100, "Query number of results returned per page")

return cmd
Expand Down Expand Up @@ -148,57 +146,3 @@ func GetValidators(ctx context.Context, clientCtx client.Context, height *int64,

return out, nil
}

// REST

// Validator Set at a height REST handler
func ValidatorSetRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 100)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse pagination parameters")
return
}

vars := mux.Vars(r)
height, err := strconv.ParseInt(vars["height"], 10, 64)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse block height")
return
}

chainHeight, err := GetChainHeight(clientCtx)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, "failed to parse chain height")
return
}
if height > chainHeight {
rest.WriteErrorResponse(w, http.StatusNotFound, "requested block height is bigger then the chain length")
return
}

output, err := GetValidators(r.Context(), clientCtx, &height, &page, &limit)
if rest.CheckInternalServerError(w, err) {
return
}
rest.PostProcessResponse(w, clientCtx, output)
}
}

// Latest Validator Set REST handler
func LatestValidatorSetRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 100)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse pagination parameters")
return
}

output, err := GetValidators(r.Context(), clientCtx, nil, &page, &limit)
if rest.CheckInternalServerError(w, err) {
return
}

rest.PostProcessResponse(w, clientCtx, output)
}
}
Loading