diff --git a/app/app.go b/app/app.go index 71bfbd58f..ce7c4a132 100644 --- a/app/app.go +++ b/app/app.go @@ -624,12 +624,6 @@ func New( } wasmConfig := wasmWrap.Wasm - // Init CosmWasm encoder integrations - encoderRegistry := provwasm.NewEncoderRegistry() - - // Init CosmWasm query integrations - querierRegistry := provwasm.NewQuerierRegistry() - // Add the capabilities and indicate that provwasm contracts can be run on this chain. // Capabilities defined here: https://github.com/CosmWasm/cosmwasm/blob/main/docs/CAPABILITIES-BUILT-IN.md supportedFeatures := []string{"staking", "provenance", "stargate", "iterator", "cosmwasm_1_1", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", "cosmwasm_2_0", "cosmwasm_2_1"} @@ -654,8 +648,7 @@ func New( wasmConfig, supportedFeatures, govAuthority, - wasmkeeper.WithQueryPlugins(provwasm.QueryPlugins(querierRegistry, *app.GRPCQueryRouter(), appCodec)), - wasmkeeper.WithMessageEncoders(provwasm.MessageEncoders(encoderRegistry, logger)), + wasmkeeper.WithQueryPlugins(provwasm.QueryPlugins(*app.GRPCQueryRouter(), appCodec)), ) app.WasmKeeper = &wasmKeeperInstance diff --git a/internal/provwasm/query_plugins.go b/internal/provwasm/query_plugins.go index f1de46fda..6161a2b78 100644 --- a/internal/provwasm/query_plugins.go +++ b/internal/provwasm/query_plugins.go @@ -13,7 +13,6 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/gogoproto/proto" provwasmtypes "github.com/provenance-io/provenance/x/wasm/types" @@ -46,7 +45,7 @@ func (qr *QuerierRegistry) RegisterQuerier(route string, querier Querier) { } // QueryPlugins provides provenance query support for smart contracts. -func QueryPlugins(registry *QuerierRegistry, queryRouter baseapp.GRPCQueryRouter, cdc codec.Codec) *wasmkeeper.QueryPlugins { +func QueryPlugins(queryRouter baseapp.GRPCQueryRouter, cdc codec.Codec) *wasmkeeper.QueryPlugins { protoCdc, ok := cdc.(*codec.ProtoCodec) if !ok { panic(fmt.Errorf("codec must be *codec.ProtoCodec type: actual: %T", cdc)) @@ -55,43 +54,11 @@ func QueryPlugins(registry *QuerierRegistry, queryRouter baseapp.GRPCQueryRouter stargateCdc := codec.NewProtoCodec(provwasmtypes.NewWasmInterfaceRegistry(protoCdc.InterfaceRegistry())) return &wasmkeeper.QueryPlugins{ - Custom: customPlugins(registry), Stargate: StargateQuerier(queryRouter, stargateCdc), Grpc: GrpcQuerier(queryRouter), } } -// Custom provenance queriers for CosmWasm integration. -func customPlugins(registry *QuerierRegistry) wasmkeeper.CustomQuerier { - return func(ctx sdk.Context, request json.RawMessage) ([]byte, error) { - req := QueryRequest{} - if err := json.Unmarshal(request, &req); err != nil { - ctx.Logger().Error("failed to unmarshal query request", "err", err) - return nil, sdkerrors.ErrJSONUnmarshal.Wrap(err.Error()) - } - query, exists := registry.queriers[req.Route] - if !exists { - ctx.Logger().Error("querier not found", "route", req.Route) - return nil, sdkerrors.ErrInvalidRequest.Wrapf("querier not found for route: %s", req.Route) - } - bz, err := query(ctx, req.Params, req.Version) - if err != nil { - ctx.Logger().Error("failed to execute query", "err", err) - return nil, sdkerrors.ErrInvalidRequest.Wrap(err.Error()) - } - if len(bz) > maxQueryResultSize { - errm := "query result size limit exceeded" - ctx.Logger().Error(errm, "maxQueryResultSize", maxQueryResultSize) - return nil, sdkerrors.ErrInvalidRequest.Wrap(errm) - } - if !json.Valid(bz) { - ctx.Logger().Error("invalid querier JSON", "route", req.Route) - return nil, sdkerrors.ErrJSONMarshal.Wrapf("invalid querier JSON from route: %s", req.Route) - } - return bz, nil - } -} - // StargateQuerier dispatches whitelisted stargate queries func StargateQuerier(queryRouter baseapp.GRPCQueryRouter, cdc codec.Codec) func(ctx sdk.Context, request *wasmvmtypes.StargateQuery) ([]byte, error) { return func(ctx sdk.Context, request *wasmvmtypes.StargateQuery) ([]byte, error) { @@ -143,6 +110,8 @@ func GrpcQuerier(queryRouter baseapp.GRPCQueryRouter) func(ctx sdk.Context, requ return nil, err } + ctx.Logger().Error("GRPC RESPONSE", "res", proto.MarshalTextString(res)) + return res, nil } }