Skip to content
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

remove old provwasm bindings #2119

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* remove old provwasm bindings [#2119](https://github.com/provenance-io/provenance/pull/2119).
23 changes: 1 addition & 22 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ import (
"github.com/provenance-io/provenance/x/attribute"
attributekeeper "github.com/provenance-io/provenance/x/attribute/keeper"
attributetypes "github.com/provenance-io/provenance/x/attribute/types"
attributewasm "github.com/provenance-io/provenance/x/attribute/wasm"
"github.com/provenance-io/provenance/x/exchange"
exchangekeeper "github.com/provenance-io/provenance/x/exchange/keeper"
exchangemodule "github.com/provenance-io/provenance/x/exchange/module"
Expand All @@ -161,19 +160,15 @@ import (
"github.com/provenance-io/provenance/x/marker"
markerkeeper "github.com/provenance-io/provenance/x/marker/keeper"
markertypes "github.com/provenance-io/provenance/x/marker/types"
markerwasm "github.com/provenance-io/provenance/x/marker/wasm"
"github.com/provenance-io/provenance/x/metadata"
metadatakeeper "github.com/provenance-io/provenance/x/metadata/keeper"
metadatatypes "github.com/provenance-io/provenance/x/metadata/types"
metadatawasm "github.com/provenance-io/provenance/x/metadata/wasm"
msgfeeskeeper "github.com/provenance-io/provenance/x/msgfees/keeper"
msgfeesmodule "github.com/provenance-io/provenance/x/msgfees/module"
msgfeestypes "github.com/provenance-io/provenance/x/msgfees/types"
msgfeeswasm "github.com/provenance-io/provenance/x/msgfees/wasm"
"github.com/provenance-io/provenance/x/name"
namekeeper "github.com/provenance-io/provenance/x/name/keeper"
nametypes "github.com/provenance-io/provenance/x/name/types"
namewasm "github.com/provenance-io/provenance/x/name/wasm"
oraclekeeper "github.com/provenance-io/provenance/x/oracle/keeper"
oraclemodule "github.com/provenance-io/provenance/x/oracle/module"
oracletypes "github.com/provenance-io/provenance/x/oracle/types"
Expand Down Expand Up @@ -629,21 +624,6 @@ func New(
}
wasmConfig := wasmWrap.Wasm

// Init CosmWasm encoder integrations
encoderRegistry := provwasm.NewEncoderRegistry()
encoderRegistry.RegisterEncoder(nametypes.RouterKey, namewasm.Encoder)
encoderRegistry.RegisterEncoder(attributetypes.RouterKey, attributewasm.Encoder)
encoderRegistry.RegisterEncoder(markertypes.RouterKey, markerwasm.Encoder)
encoderRegistry.RegisterEncoder(metadatatypes.RouterKey, metadatawasm.Encoder)
encoderRegistry.RegisterEncoder(msgfeestypes.RouterKey, msgfeeswasm.Encoder)

// Init CosmWasm query integrations
querierRegistry := provwasm.NewQuerierRegistry()
querierRegistry.RegisterQuerier(nametypes.RouterKey, namewasm.Querier(app.NameKeeper))
querierRegistry.RegisterQuerier(attributetypes.RouterKey, attributewasm.Querier(app.AttributeKeeper))
querierRegistry.RegisterQuerier(markertypes.RouterKey, markerwasm.Querier(app.MarkerKeeper))
querierRegistry.RegisterQuerier(metadatatypes.RouterKey, metadatawasm.Querier(app.MetadataKeeper))

// 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 @@ -668,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
75 changes: 0 additions & 75 deletions internal/provwasm/message_encoders.go

This file was deleted.

38 changes: 1 addition & 37 deletions internal/provwasm/query_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@ 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"
)

// The maximum querier result size allowed, ~10MB.
const maxQueryResultSize = (10 << 20) - 1

// Querier describes behavior for provenance smart contract query support.
type Querier func(ctx sdk.Context, query json.RawMessage, version string) ([]byte, error)

Expand All @@ -46,7 +42,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 +51,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
27 changes: 0 additions & 27 deletions internal/provwasm/requests.go

This file was deleted.

Loading
Loading