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

change provwasm stargate query plugin to use protocodec #2034

Merged
merged 9 commits into from
Jun 20, 2024
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 11 additions & 2 deletions internal/provwasm/query_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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),
}
}

Expand Down
19 changes: 19 additions & 0 deletions x/wasm/types/any.go
Original file line number Diff line number Diff line change
@@ -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
}
23 changes: 23 additions & 0 deletions x/wasm/types/interface_registry.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading