diff --git a/baseapp/abci.go b/baseapp/abci.go index 6c6bd2f81e..924a9f8191 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -420,9 +420,6 @@ func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) { case QueryPathP2P: return handleQueryP2P(app, path) - - case QueryPathCustom: - return handleQueryCustom(app, path, req) } return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown query path"), app.trace) @@ -816,43 +813,6 @@ func handleQueryP2P(app *BaseApp, path []string) abci.ResponseQuery { return resp } -func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) abci.ResponseQuery { - // path[0] should be "custom" because "/custom" prefix is required for keeper - // queries. - // - // The QueryRouter routes using path[1]. For example, in the path - // "custom/gov/proposal", QueryRouter routes using "gov". - if len(path) < 2 || path[1] == "" { - return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "no route for custom query specified"), app.trace) - } - - querier := app.queryRouter.Route(path[1]) - if querier == nil { - return sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "no custom querier found for route %s", path[1]), app.trace) - } - - ctx, err := app.createQueryContext(req.Height, req.Prove) - if err != nil { - return sdkerrors.QueryResult(err, app.trace) - } - - // Passes the rest of the path as an argument to the querier. - // - // For example, in the path "custom/gov/proposal/test", the gov querier gets - // []string{"proposal", "test"} as the path. - resBytes, err := querier(ctx, path[2:], req) - if err != nil { - res := sdkerrors.QueryResult(err, app.trace) - res.Height = req.Height - return res - } - - return abci.ResponseQuery{ - Height: req.Height, - Value: resBytes, - } -} - // SplitABCIQueryPath splits a string path using the delimiter '/'. // // e.g. "this/is/funny" becomes []string{"this", "is", "funny"} diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index e199a67c2f..cab7aa27e5 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -48,7 +48,6 @@ type BaseApp struct { //nolint: maligned db dbm.DB // common DB backend cms sdk.CommitMultiStore // Main (uncached) state storeLoader StoreLoader // function to handle store loading, may be overridden with SetStoreLoader() - queryRouter sdk.QueryRouter // router for redirecting query calls grpcQueryRouter *GRPCQueryRouter // router for redirecting gRPC query calls msgServiceRouter *MsgServiceRouter // router for redirecting Msg service messages interfaceRegistry codectypes.InterfaceRegistry @@ -147,7 +146,6 @@ func NewBaseApp( db: db, cms: store.NewCommitMultiStore(db), storeLoader: DefaultStoreLoader, - queryRouter: NewQueryRouter(), grpcQueryRouter: NewGRPCQueryRouter(), msgServiceRouter: NewMsgServiceRouter(), txDecoder: txDecoder, @@ -364,9 +362,6 @@ func (app *BaseApp) setIndexEvents(ie []string) { } } -// QueryRouter returns the QueryRouter of a BaseApp. -func (app *BaseApp) QueryRouter() sdk.QueryRouter { return app.queryRouter } - // Seal seals a BaseApp. It prohibits any further modifications to a BaseApp. func (app *BaseApp) Seal() { app.sealed = true } diff --git a/baseapp/queryrouter.go b/baseapp/queryrouter.go deleted file mode 100644 index 1727b2ab2d..0000000000 --- a/baseapp/queryrouter.go +++ /dev/null @@ -1,41 +0,0 @@ -package baseapp - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -type QueryRouter struct { - routes map[string]sdk.Querier -} - -var _ sdk.QueryRouter = NewQueryRouter() - -// NewQueryRouter returns a reference to a new QueryRouter. -func NewQueryRouter() *QueryRouter { - return &QueryRouter{ - routes: map[string]sdk.Querier{}, - } -} - -// AddRoute adds a query path to the router with a given Querier. It will panic -// if a duplicate route is given. The route must be alphanumeric. -func (qrt *QueryRouter) AddRoute(path string, q sdk.Querier) sdk.QueryRouter { - if !sdk.IsAlphaNumeric(path) { - panic("route expressions can only contain alphanumeric characters") - } - - if qrt.routes[path] != nil { - panic(fmt.Sprintf("route %s has already been initialized", path)) - } - - qrt.routes[path] = q - - return qrt -} - -// Route returns the Querier for a given query route path. -func (qrt *QueryRouter) Route(path string) sdk.Querier { - return qrt.routes[path] -} diff --git a/baseapp/queryrouter_test.go b/baseapp/queryrouter_test.go deleted file mode 100644 index c7637f1700..0000000000 --- a/baseapp/queryrouter_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package baseapp - -import ( - "testing" - - "github.com/stretchr/testify/require" - - abci "github.com/tendermint/tendermint/abci/types" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -var testQuerier = func(_ sdk.Context, _ []string, _ abci.RequestQuery) ([]byte, error) { - return nil, nil -} - -func TestQueryRouter(t *testing.T) { - qr := NewQueryRouter() - - // require panic on invalid route - require.Panics(t, func() { - qr.AddRoute("*", testQuerier) - }) - - qr.AddRoute("testRoute", testQuerier) - q := qr.Route("testRoute") - require.NotNil(t, q) - - // require panic on duplicate route - require.Panics(t, func() { - qr.AddRoute("testRoute", testQuerier) - }) -}