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
14 changes: 12 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,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),
}
}

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" }

Check failure on line 11 in x/wasm/types/any.go

View workflow job for this annotation

GitHub Actions / golangci-lint

var-naming: don't use underscores in Go names; method XXX_WellKnownType should be XXXWellKnownType (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