Skip to content

Commit

Permalink
remove old custom query plugin handler
Browse files Browse the repository at this point in the history
  • Loading branch information
kwtalley committed Aug 9, 2024
1 parent 710897e commit 0ea1080
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 42 deletions.
9 changes: 1 addition & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -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

Expand Down
35 changes: 1 addition & 34 deletions internal/provwasm/query_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand All @@ -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) {
Expand Down

0 comments on commit 0ea1080

Please sign in to comment.