Skip to content

Commit

Permalink
Fix usage of deprecated wasm.
Browse files Browse the repository at this point in the history
  • Loading branch information
Taztingo committed May 21, 2024
1 parent d3f50fa commit 4eaed37
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions internal/provwasm/message_encoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"fmt"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"

"cosmossdk.io/log"

Expand Down Expand Up @@ -40,14 +40,14 @@ func (qr *EncoderRegistry) RegisterEncoder(route string, encoder Encoder) {
}

// MessageEncoders provides provenance message encoding support for smart contracts.
func MessageEncoders(registry *EncoderRegistry, logger log.Logger) *wasm.MessageEncoders {
return &wasm.MessageEncoders{
func MessageEncoders(registry *EncoderRegistry, logger log.Logger) *wasmkeeper.MessageEncoders {
return &wasmkeeper.MessageEncoders{
Custom: customEncoders(registry, logger),
}
}

// Custom provenance encoders for CosmWasm integration.
func customEncoders(registry *EncoderRegistry, logger log.Logger) wasm.CustomEncoder {
func customEncoders(registry *EncoderRegistry, logger log.Logger) wasmkeeper.CustomEncoder {
return func(contract sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error) {
req := EncodeRequest{}
if err := json.Unmarshal(msg, &req); err != nil {
Expand Down
11 changes: 6 additions & 5 deletions internal/provwasm/query_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"fmt"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"

abci "github.com/cometbft/cometbft/abci/types"
Expand All @@ -14,6 +14,7 @@ import (
"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"
)

// The maximum querier result size allowed, ~10MB.
Expand Down Expand Up @@ -43,15 +44,15 @@ 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) *wasm.QueryPlugins {
return &wasm.QueryPlugins{
func QueryPlugins(registry *QuerierRegistry, queryRouter baseapp.GRPCQueryRouter, codec codec.Codec) *wasmkeeper.QueryPlugins {
return &wasmkeeper.QueryPlugins{
Custom: customPlugins(registry),
Stargate: StargateQuerier(queryRouter, codec),
}
}

// Custom provenance queriers for CosmWasm integration.
func customPlugins(registry *QuerierRegistry) wasm.CustomQuerier {
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 {
Expand Down Expand Up @@ -114,7 +115,7 @@ func StargateQuerier(queryRouter baseapp.GRPCQueryRouter, cdc codec.Codec) func(
// ConvertProtoToJsonMarshal unmarshals the given bytes into a proto message and then marshals it to json.
// This is done so that clients calling stargate queries do not need to define their own proto unmarshalers,
// being able to use response directly by json marshaling, which is supported in cosmwasm.
func ConvertProtoToJSONMarshal(protoResponseType codec.ProtoMarshaler, bz []byte, cdc codec.Codec) ([]byte, error) {
func ConvertProtoToJSONMarshal(protoResponseType proto.Message, bz []byte, cdc codec.Codec) ([]byte, error) {
// unmarshal binary into stargate response data structure
err := cdc.Unmarshal(bz, protoResponseType)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/provwasm/stargate_whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (

wasmvmtypes "github.com/CosmWasm/wasmvm/types"

"github.com/cosmos/cosmos-sdk/codec"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/gogoproto/proto"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"

attributetypes "github.com/provenance-io/provenance/x/attribute/types"
Expand Down Expand Up @@ -141,19 +141,19 @@ func init() {

// GetWhitelistedQuery returns the whitelisted query at the provided path.
// If the query does not exist, or it was setup wrong by the chain, this returns an error.
func GetWhitelistedQuery(queryPath string) (codec.ProtoMarshaler, error) {
func GetWhitelistedQuery(queryPath string) (proto.Message, error) {
protoResponseAny, isWhitelisted := stargateWhitelist.Load(queryPath)
if !isWhitelisted {
return nil, wasmvmtypes.UnsupportedRequest{Kind: fmt.Sprintf("'%s' path is not allowed from the contract", queryPath)}
}
protoResponseType, ok := protoResponseAny.(codec.ProtoMarshaler)
protoResponseType, ok := protoResponseAny.(proto.Message)
if !ok {
return nil, wasmvmtypes.Unknown{}
}
return protoResponseType, nil
}

func setWhitelistedQuery(queryPath string, protoType codec.ProtoMarshaler) {
func setWhitelistedQuery(queryPath string, protoType proto.Message) {
stargateWhitelist.Store(queryPath, protoType)
}

Expand Down

0 comments on commit 4eaed37

Please sign in to comment.