diff --git a/app/app.go b/app/app.go index e47401ce5..37979fd02 100644 --- a/app/app.go +++ b/app/app.go @@ -644,9 +644,9 @@ func New( querierRegistry.RegisterQuerier(markertypes.RouterKey, markerwasm.Querier(app.MarkerKeeper)) querierRegistry.RegisterQuerier(metadatatypes.RouterKey, metadatawasm.Querier(app.MetadataKeeper)) - // Add the staking feature and indicate that provwasm contracts can be run on this chain. - // Addition of cosmwasm_1_1 adds capability defined here: https://github.com/CosmWasm/cosmwasm/pull/1356 - supportedFeatures := "staking,provenance,stargate,iterator,cosmwasm_1_1" + // 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 := "staking,provenance,stargate,iterator,cosmwasm_1_1, cosmwasm_1_2, cosmwasm_1_3, cosmwasm_1_4" // The last arguments contain custom message handlers, and custom query handlers, // to allow smart contracts to use provenance modules. diff --git a/internal/provwasm/query_plugins.go b/internal/provwasm/query_plugins.go index 6a3129b7e..ad71bc1fa 100644 --- a/internal/provwasm/query_plugins.go +++ b/internal/provwasm/query_plugins.go @@ -15,6 +15,8 @@ import ( 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. @@ -44,10 +46,17 @@ func (qr *QuerierRegistry) RegisterQuerier(route string, querier Querier) { } // QueryPlugins provides provenance query support for smart contracts. -func QueryPlugins(registry *QuerierRegistry, queryRouter baseapp.GRPCQueryRouter, codec codec.Codec) *wasmkeeper.QueryPlugins { +func QueryPlugins(registry *QuerierRegistry, 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)) + } + + stargateCdc := codec.NewProtoCodec(provwasmtypes.NewWasmInterfaceRegistry(protoCdc.InterfaceRegistry())) + return &wasmkeeper.QueryPlugins{ Custom: customPlugins(registry), - Stargate: StargateQuerier(queryRouter, codec), + Stargate: StargateQuerier(queryRouter, stargateCdc), } } diff --git a/x/wasm/types/any.go b/x/wasm/types/any.go new file mode 100644 index 000000000..aa1643d89 --- /dev/null +++ b/x/wasm/types/any.go @@ -0,0 +1,19 @@ +package types + +import fmt "fmt" + +// WasmAny represents the type with raw bytes value for codectypes.Any +type WasmAny struct { + Value []byte +} + +func (*WasmAny) ProtoMessage() {} +func (*WasmAny) XXX_WellKnownType() string { return "BytesValue" } //nolint:revive +func (m *WasmAny) Reset() { *m = WasmAny{} } +func (m *WasmAny) String() string { + return fmt.Sprintf("%x", m.Value) // not compatible w/ pb oct +} +func (m *WasmAny) Unmarshal(b []byte) error { + m.Value = append([]byte(nil), b...) + return nil +} diff --git a/x/wasm/types/interface_registry.go b/x/wasm/types/interface_registry.go new file mode 100644 index 000000000..f98dafec8 --- /dev/null +++ b/x/wasm/types/interface_registry.go @@ -0,0 +1,23 @@ +package types + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/gogoproto/proto" +) + +var _ codectypes.InterfaceRegistry = &WasmInterfaceRegistry{} + +// NewWasmInterfaceRegistry returns a new WasmInterfaceRegistry instance +func NewWasmInterfaceRegistry(registry codectypes.InterfaceRegistry) WasmInterfaceRegistry { + return WasmInterfaceRegistry{registry} +} + +// WasmInterfaceRegistry represents an interface registry with a custom any resolver +type WasmInterfaceRegistry struct { + codectypes.InterfaceRegistry +} + +// Resolve implements codectypes.InterfaceRegistry +func (WasmInterfaceRegistry) Resolve(_ string) (proto.Message, error) { + return new(WasmAny), nil +}