From bf6e8da83218b10e49158428f731d70035659ea1 Mon Sep 17 00:00:00 2001 From: kwt <4344285+kwtalley@users.noreply.github.com> Date: Thu, 30 Nov 2023 21:28:34 -0600 Subject: [PATCH 1/7] change provwasm stargate query plugin to use protocodec with WasmAny type --- internal/provwasm/query_plugins.go | 14 ++++++++++++-- x/wasm/types/any.go | 19 +++++++++++++++++++ x/wasm/types/interface_registry.go | 24 ++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 x/wasm/types/any.go create mode 100644 x/wasm/types/interface_registry.go diff --git a/internal/provwasm/query_plugins.go b/internal/provwasm/query_plugins.go index 6a3129b7e0..e7e290871e 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,18 @@ 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 0000000000..3656aa41fd --- /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" } +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 0000000000..d3758a5fde --- /dev/null +++ b/x/wasm/types/interface_registry.go @@ -0,0 +1,24 @@ +package types + +import ( + "github.com/cosmos/gogoproto/proto" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" +) + +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(typeUrl string) (proto.Message, error) { + return new(WasmAny), nil +} From 4abb82723ff7f0d91a53724713fc3ef8ba5126d0 Mon Sep 17 00:00:00 2001 From: kwt <4344285+kwtalley@users.noreply.github.com> Date: Fri, 14 Jun 2024 13:17:16 -0500 Subject: [PATCH 2/7] fix lint issue --- x/wasm/types/interface_registry.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/wasm/types/interface_registry.go b/x/wasm/types/interface_registry.go index d3758a5fde..5485afa0bc 100644 --- a/x/wasm/types/interface_registry.go +++ b/x/wasm/types/interface_registry.go @@ -19,6 +19,6 @@ type WasmInterfaceRegistry struct { } // Resolve implements codectypes.InterfaceRegistry -func (WasmInterfaceRegistry) Resolve(typeUrl string) (proto.Message, error) { +func (WasmInterfaceRegistry) Resolve(_ string) (proto.Message, error) { return new(WasmAny), nil } From 613b51118224866a546ea9d1ac3a7ecc7da06dec Mon Sep 17 00:00:00 2001 From: kwt <4344285+kwtalley@users.noreply.github.com> Date: Fri, 14 Jun 2024 13:30:19 -0500 Subject: [PATCH 3/7] fix imports lint issue --- x/wasm/types/interface_registry.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/wasm/types/interface_registry.go b/x/wasm/types/interface_registry.go index 5485afa0bc..f98dafec8c 100644 --- a/x/wasm/types/interface_registry.go +++ b/x/wasm/types/interface_registry.go @@ -1,9 +1,8 @@ package types import ( - "github.com/cosmos/gogoproto/proto" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/gogoproto/proto" ) var _ codectypes.InterfaceRegistry = &WasmInterfaceRegistry{} From 154de11b8d781689c320e814cc8eb0552203d91d Mon Sep 17 00:00:00 2001 From: kwt <4344285+kwtalley@users.noreply.github.com> Date: Fri, 14 Jun 2024 18:47:04 -0500 Subject: [PATCH 4/7] update cosmwasm capabilities to 1_4 --- app/app.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/app.go b/app/app.go index 47c89f8706..f59c24a469 100644 --- a/app/app.go +++ b/app/app.go @@ -647,9 +647,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_4" // The last arguments contain custom message handlers, and custom query handlers, // to allow smart contracts to use provenance modules. From 0fc8e814791240008b9d3a88f91d5449ba7362a0 Mon Sep 17 00:00:00 2001 From: kwt <4344285+kwtalley@users.noreply.github.com> Date: Thu, 20 Jun 2024 13:41:59 -0500 Subject: [PATCH 5/7] add lint ignore to function --- x/wasm/types/any.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/wasm/types/any.go b/x/wasm/types/any.go index 3656aa41fd..aa1643d893 100644 --- a/x/wasm/types/any.go +++ b/x/wasm/types/any.go @@ -8,7 +8,7 @@ type WasmAny struct { } func (*WasmAny) ProtoMessage() {} -func (*WasmAny) XXX_WellKnownType() string { return "BytesValue" } +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 From d8f95b5295357e2a3342562991ab19c46a5cf8a6 Mon Sep 17 00:00:00 2001 From: kwt <4344285+kwtalley@users.noreply.github.com> Date: Thu, 20 Jun 2024 13:49:30 -0500 Subject: [PATCH 6/7] fix lint newline --- internal/provwasm/query_plugins.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/provwasm/query_plugins.go b/internal/provwasm/query_plugins.go index e7e290871e..ad71bc1fad 100644 --- a/internal/provwasm/query_plugins.go +++ b/internal/provwasm/query_plugins.go @@ -47,7 +47,6 @@ 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 { - protoCdc, ok := cdc.(*codec.ProtoCodec) if !ok { panic(fmt.Errorf("codec must be *codec.ProtoCodec type: actual: %T", cdc)) From 0ef12d26ad87ad3ea9b0fb7969e880ad49066de6 Mon Sep 17 00:00:00 2001 From: kwt <4344285+kwtalley@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:34:15 -0500 Subject: [PATCH 7/7] add previous cosmwasm release capabilities --- app/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app.go b/app/app.go index 250f3940d7..37979fd020 100644 --- a/app/app.go +++ b/app/app.go @@ -646,7 +646,7 @@ func New( // 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_4" + 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.