diff --git a/.golangci.yml b/.golangci.yml index 17d5384ea..54497acc4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,7 +5,6 @@ linters: disable-all: true enable: - bodyclose - - deadcode - depguard - dogsled - errcheck @@ -23,12 +22,10 @@ linters: - prealloc - exportloopref - staticcheck - - structcheck - stylecheck - typecheck - unconvert - unused - - varcheck issues: exclude-rules: diff --git a/Makefile b/Makefile index 9ec0fa07a..f24ccc457 100644 --- a/Makefile +++ b/Makefile @@ -163,10 +163,10 @@ format-tools: lint: format-tools golangci-lint run --tests=false - find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofumpt -d -s + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofumpt -d format: format-tools - find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofumpt -w -s + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofumpt -w find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs misspell -w find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs goimports -w -local github.com/CosmWasm/wasmd diff --git a/app/ante.go b/app/ante.go index 56828d7a2..e408372fa 100644 --- a/app/ante.go +++ b/app/ante.go @@ -1,6 +1,7 @@ package app import ( + errorsmod "cosmossdk.io/errors" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -24,19 +25,19 @@ type HandlerOptions struct { func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { if options.AccountKeeper == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler") + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler") } if options.BankKeeper == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler") + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler") } if options.SignModeHandler == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") } if options.WasmConfig == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder") + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder") } if options.TXCounterStoreKey == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder") + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder") } anteDecorators := []sdk.AnteDecorator{ diff --git a/x/wasm/client/cli/new_tx.go b/x/wasm/client/cli/new_tx.go index d7e477a9f..f15319c09 100644 --- a/x/wasm/client/cli/new_tx.go +++ b/x/wasm/client/cli/new_tx.go @@ -3,10 +3,10 @@ package cli import ( "strconv" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/spf13/cobra" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -44,7 +44,7 @@ func parseMigrateContractArgs(args []string, cliCtx client.Context) (types.MsgMi // get the id of the code to instantiate codeID, err := strconv.ParseUint(args[1], 10, 64) if err != nil { - return types.MsgMigrateContract{}, sdkerrors.Wrap(err, "code id") + return types.MsgMigrateContract{}, errorsmod.Wrap(err, "code id") } migrateMsg := args[2] diff --git a/x/wasm/ibc.go b/x/wasm/ibc.go index 01e3703c8..b310e04cc 100644 --- a/x/wasm/ibc.go +++ b/x/wasm/ibc.go @@ -3,9 +3,9 @@ package wasm import ( "math" + errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" @@ -50,7 +50,7 @@ func (i IBCHandler) OnChanOpenInit( } contractAddr, err := ContractFromPortID(portID) if err != nil { - return "", sdkerrors.Wrapf(err, "contract port id") + return "", errorsmod.Wrapf(err, "contract port id") } msg := wasmvmtypes.IBCChannelOpenMsg{ @@ -77,7 +77,7 @@ func (i IBCHandler) OnChanOpenInit( // Claim channel capability passed back by IBC module if err := i.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { - return "", sdkerrors.Wrap(err, "claim capability") + return "", errorsmod.Wrap(err, "claim capability") } return acceptedVersion, nil } @@ -99,7 +99,7 @@ func (i IBCHandler) OnChanOpenTry( contractAddr, err := ContractFromPortID(portID) if err != nil { - return "", sdkerrors.Wrapf(err, "contract port id") + return "", errorsmod.Wrapf(err, "contract port id") } msg := wasmvmtypes.IBCChannelOpenMsg{ @@ -131,7 +131,7 @@ func (i IBCHandler) OnChanOpenTry( if !i.keeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { // Only claim channel capability passed back by IBC module if we do not already own it if err := i.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { - return "", sdkerrors.Wrap(err, "claim capability") + return "", errorsmod.Wrap(err, "claim capability") } } @@ -147,17 +147,17 @@ func (i IBCHandler) OnChanOpenAck( ) error { contractAddr, err := ContractFromPortID(portID) if err != nil { - return sdkerrors.Wrapf(err, "contract port id") + return errorsmod.Wrapf(err, "contract port id") } channelInfo, ok := i.channelKeeper.GetChannel(ctx, portID, channelID) if !ok { - return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } channelInfo.Counterparty.ChannelId = counterpartyChannelID appVersion, ok := i.appVersionGetter.GetAppVersion(ctx, portID, channelID) if !ok { - return sdkerrors.Wrapf(channeltypes.ErrInvalidChannelVersion, "port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(channeltypes.ErrInvalidChannelVersion, "port ID (%s) channel ID (%s)", portID, channelID) } msg := wasmvmtypes.IBCChannelConnectMsg{ @@ -173,15 +173,15 @@ func (i IBCHandler) OnChanOpenAck( func (i IBCHandler) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string) error { contractAddr, err := ContractFromPortID(portID) if err != nil { - return sdkerrors.Wrapf(err, "contract port id") + return errorsmod.Wrapf(err, "contract port id") } channelInfo, ok := i.channelKeeper.GetChannel(ctx, portID, channelID) if !ok { - return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } appVersion, ok := i.appVersionGetter.GetAppVersion(ctx, portID, channelID) if !ok { - return sdkerrors.Wrapf(channeltypes.ErrInvalidChannelVersion, "port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(channeltypes.ErrInvalidChannelVersion, "port ID (%s) channel ID (%s)", portID, channelID) } msg := wasmvmtypes.IBCChannelConnectMsg{ OpenConfirm: &wasmvmtypes.IBCOpenConfirm{ @@ -195,15 +195,15 @@ func (i IBCHandler) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string) func (i IBCHandler) OnChanCloseInit(ctx sdk.Context, portID, channelID string) error { contractAddr, err := ContractFromPortID(portID) if err != nil { - return sdkerrors.Wrapf(err, "contract port id") + return errorsmod.Wrapf(err, "contract port id") } channelInfo, ok := i.channelKeeper.GetChannel(ctx, portID, channelID) if !ok { - return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } appVersion, ok := i.appVersionGetter.GetAppVersion(ctx, portID, channelID) if !ok { - return sdkerrors.Wrapf(channeltypes.ErrInvalidChannelVersion, "port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(channeltypes.ErrInvalidChannelVersion, "port ID (%s) channel ID (%s)", portID, channelID) } msg := wasmvmtypes.IBCChannelCloseMsg{ @@ -223,15 +223,15 @@ func (i IBCHandler) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string // counterparty has closed the channel contractAddr, err := ContractFromPortID(portID) if err != nil { - return sdkerrors.Wrapf(err, "contract port id") + return errorsmod.Wrapf(err, "contract port id") } channelInfo, ok := i.channelKeeper.GetChannel(ctx, portID, channelID) if !ok { - return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } appVersion, ok := i.appVersionGetter.GetAppVersion(ctx, portID, channelID) if !ok { - return sdkerrors.Wrapf(channeltypes.ErrInvalidChannelVersion, "port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(channeltypes.ErrInvalidChannelVersion, "port ID (%s) channel ID (%s)", portID, channelID) } msg := wasmvmtypes.IBCChannelCloseMsg{ @@ -264,7 +264,7 @@ func (i IBCHandler) OnRecvPacket( ) ibcexported.Acknowledgement { contractAddr, err := ContractFromPortID(packet.DestinationPort) if err != nil { - return channeltypes.NewErrorAcknowledgement(sdkerrors.Wrapf(err, "contract port id")) + return channeltypes.NewErrorAcknowledgement(errorsmod.Wrapf(err, "contract port id")) } msg := wasmvmtypes.IBCPacketReceiveMsg{Packet: newIBCPacket(packet), Relayer: relayer.String()} ack, err := i.keeper.OnRecvPacket(ctx, contractAddr, msg) @@ -295,7 +295,7 @@ func (i IBCHandler) OnAcknowledgementPacket( ) error { contractAddr, err := ContractFromPortID(packet.SourcePort) if err != nil { - return sdkerrors.Wrapf(err, "contract port id") + return errorsmod.Wrapf(err, "contract port id") } err = i.keeper.OnAckPacket(ctx, contractAddr, wasmvmtypes.IBCPacketAckMsg{ @@ -304,7 +304,7 @@ func (i IBCHandler) OnAcknowledgementPacket( Relayer: relayer.String(), }) if err != nil { - return sdkerrors.Wrap(err, "on ack") + return errorsmod.Wrap(err, "on ack") } return nil } @@ -313,12 +313,12 @@ func (i IBCHandler) OnAcknowledgementPacket( func (i IBCHandler) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) error { contractAddr, err := ContractFromPortID(packet.SourcePort) if err != nil { - return sdkerrors.Wrapf(err, "contract port id") + return errorsmod.Wrapf(err, "contract port id") } msg := wasmvmtypes.IBCPacketTimeoutMsg{Packet: newIBCPacket(packet), Relayer: relayer.String()} err = i.keeper.OnTimeoutPacket(ctx, contractAddr, msg) if err != nil { - return sdkerrors.Wrap(err, "on timeout") + return errorsmod.Wrap(err, "on timeout") } return nil } @@ -351,7 +351,7 @@ func ValidateChannelParams(channelID string) error { return err } if channelSequence > math.MaxUint32 { - return sdkerrors.Wrapf(types.ErrMaxIBCChannels, "channel sequence %d is greater than max allowed transfer channels %d", channelSequence, math.MaxUint32) + return errorsmod.Wrapf(types.ErrMaxIBCChannels, "channel sequence %d is greater than max allowed transfer channels %d", channelSequence, math.MaxUint32) } return nil } diff --git a/x/wasm/ibctesting/chain.go b/x/wasm/ibctesting/chain.go index 98afa3685..47f5b5608 100644 --- a/x/wasm/ibctesting/chain.go +++ b/x/wasm/ibctesting/chain.go @@ -5,17 +5,13 @@ import ( "testing" "time" + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - - "github.com/CosmWasm/wasmd/app" - "github.com/CosmWasm/wasmd/x/wasm" - - // simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" @@ -38,6 +34,9 @@ import ( tmprotoversion "github.com/tendermint/tendermint/proto/tendermint/version" tmtypes "github.com/tendermint/tendermint/types" tmversion "github.com/tendermint/tendermint/version" + + "github.com/CosmWasm/wasmd/app" + "github.com/CosmWasm/wasmd/x/wasm" ) var MaxAccounts = 10 @@ -433,7 +432,7 @@ func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterpa // NextValidatorsHash tmTrustedVals, ok = counterparty.GetValsAtHeight(int64(trustedHeight.RevisionHeight + 1)) if !ok { - return nil, sdkerrors.Wrapf(ibctm.ErrInvalidHeaderHeight, "could not retrieve trusted validators at trustedHeight: %d", trustedHeight) + return nil, errorsmod.Wrapf(ibctm.ErrInvalidHeaderHeight, "could not retrieve trusted validators at trustedHeight: %d", trustedHeight) } } // inject trusted fields into last header diff --git a/x/wasm/keeper/events.go b/x/wasm/keeper/events.go index 03cb7ea77..06807f1c2 100644 --- a/x/wasm/keeper/events.go +++ b/x/wasm/keeper/events.go @@ -4,9 +4,10 @@ import ( "fmt" "strings" + errorsmod "cosmossdk.io/errors" + wasmvmtypes "github.com/CosmWasm/wasmvm/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -31,7 +32,7 @@ func newCustomEvents(evts wasmvmtypes.Events, contractAddr sdk.AccAddress) (sdk. for _, e := range evts { typ := strings.TrimSpace(e.Type) if len(typ) <= eventTypeMinLength { - return nil, sdkerrors.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Event type too short: '%s'", typ)) + return nil, errorsmod.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Event type too short: '%s'", typ)) } attributes, err := contractSDKEventAttributes(e.Attributes, contractAddr) if err != nil { @@ -50,16 +51,16 @@ func contractSDKEventAttributes(customAttributes []wasmvmtypes.EventAttribute, c // ensure key and value are non-empty (and trim what is there) key := strings.TrimSpace(l.Key) if len(key) == 0 { - return nil, sdkerrors.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Empty attribute key. Value: %s", l.Value)) + return nil, errorsmod.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Empty attribute key. Value: %s", l.Value)) } value := strings.TrimSpace(l.Value) // TODO: check if this is legal in the SDK - if it is, we can remove this check if len(value) == 0 { - return nil, sdkerrors.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Empty attribute value. Key: %s", key)) + return nil, errorsmod.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Empty attribute value. Key: %s", key)) } // and reserve all _* keys for our use (not contract) if strings.HasPrefix(key, types.AttributeReservedPrefix) { - return nil, sdkerrors.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Attribute key starts with reserved prefix %s: '%s'", types.AttributeReservedPrefix, key)) + return nil, errorsmod.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Attribute key starts with reserved prefix %s: '%s'", types.AttributeReservedPrefix, key)) } attrs = append(attrs, sdk.NewAttribute(key, value)) } diff --git a/x/wasm/keeper/gas_register.go b/x/wasm/keeper/gas_register.go index 7292e48c0..ad97b30c5 100644 --- a/x/wasm/keeper/gas_register.go +++ b/x/wasm/keeper/gas_register.go @@ -1,6 +1,7 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -140,7 +141,7 @@ func NewDefaultWasmGasRegister() WasmGasRegister { // NewWasmGasRegister constructor func NewWasmGasRegister(c WasmGasRegisterConfig) WasmGasRegister { if c.GasMultiplier == 0 { - panic(sdkerrors.Wrap(sdkerrors.ErrLogic, "GasMultiplier can not be 0")) + panic(errorsmod.Wrap(sdkerrors.ErrLogic, "GasMultiplier can not be 0")) } return WasmGasRegister{ c: c, @@ -155,7 +156,7 @@ func (g WasmGasRegister) NewContractInstanceCosts(pinned bool, msgLen int) store // CompileCosts costs to persist and "compile" a new wasm contract func (g WasmGasRegister) CompileCosts(byteLength int) storetypes.Gas { if byteLength < 0 { - panic(sdkerrors.Wrap(types.ErrInvalid, "negative length")) + panic(errorsmod.Wrap(types.ErrInvalid, "negative length")) } return g.c.CompileCost * uint64(byteLength) } @@ -163,7 +164,7 @@ func (g WasmGasRegister) CompileCosts(byteLength int) storetypes.Gas { // UncompressCosts costs to unpack a new wasm contract func (g WasmGasRegister) UncompressCosts(byteLength int) sdk.Gas { if byteLength < 0 { - panic(sdkerrors.Wrap(types.ErrInvalid, "negative length")) + panic(errorsmod.Wrap(types.ErrInvalid, "negative length")) } return g.c.UncompressCost.Mul(uint64(byteLength)).Floor() } @@ -171,7 +172,7 @@ func (g WasmGasRegister) UncompressCosts(byteLength int) sdk.Gas { // InstantiateContractCosts costs when interacting with a wasm contract func (g WasmGasRegister) InstantiateContractCosts(pinned bool, msgLen int) sdk.Gas { if msgLen < 0 { - panic(sdkerrors.Wrap(types.ErrInvalid, "negative length")) + panic(errorsmod.Wrap(types.ErrInvalid, "negative length")) } dataCosts := sdk.Gas(msgLen) * g.c.ContractMessageDataCost if pinned { diff --git a/x/wasm/keeper/genesis.go b/x/wasm/keeper/genesis.go index 183c6f48b..b0e7764fa 100644 --- a/x/wasm/keeper/genesis.go +++ b/x/wasm/keeper/genesis.go @@ -1,8 +1,8 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" abci "github.com/tendermint/tendermint/abci/types" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -23,14 +23,14 @@ func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState) ([]ab for i, code := range data.Codes { err := keeper.importCode(ctx, code.CodeID, code.CodeInfo, code.CodeBytes) if err != nil { - return nil, sdkerrors.Wrapf(err, "code %d with id: %d", i, code.CodeID) + return nil, errorsmod.Wrapf(err, "code %d with id: %d", i, code.CodeID) } if code.CodeID > maxCodeID { maxCodeID = code.CodeID } if code.Pinned { if err := contractKeeper.PinCode(ctx, code.CodeID); err != nil { - return nil, sdkerrors.Wrapf(err, "contract number %d", i) + return nil, errorsmod.Wrapf(err, "contract number %d", i) } } } @@ -39,11 +39,11 @@ func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState) ([]ab for i, contract := range data.Contracts { contractAddr, err := sdk.AccAddressFromBech32(contract.ContractAddress) if err != nil { - return nil, sdkerrors.Wrapf(err, "address in contract number %d", i) + return nil, errorsmod.Wrapf(err, "address in contract number %d", i) } err = keeper.importContract(ctx, contractAddr, &contract.ContractInfo, contract.ContractState, contract.ContractCodeHistory) if err != nil { - return nil, sdkerrors.Wrapf(err, "contract number %d", i) + return nil, errorsmod.Wrapf(err, "contract number %d", i) } maxContractID = i + 1 // not ideal but max(contractID) is not persisted otherwise } @@ -51,18 +51,18 @@ func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState) ([]ab for i, seq := range data.Sequences { err := keeper.importAutoIncrementID(ctx, seq.IDKey, seq.Value) if err != nil { - return nil, sdkerrors.Wrapf(err, "sequence number %d", i) + return nil, errorsmod.Wrapf(err, "sequence number %d", i) } } // sanity check seq values seqVal := keeper.PeekAutoIncrementID(ctx, types.KeyLastCodeID) if seqVal <= maxCodeID { - return nil, sdkerrors.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeyLastCodeID), seqVal, maxCodeID) + return nil, errorsmod.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeyLastCodeID), seqVal, maxCodeID) } seqVal = keeper.PeekAutoIncrementID(ctx, types.KeyLastInstanceID) if seqVal <= uint64(maxContractID) { - return nil, sdkerrors.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeyLastInstanceID), seqVal, maxContractID) + return nil, errorsmod.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeyLastInstanceID), seqVal, maxContractID) } return nil, nil } diff --git a/x/wasm/keeper/handler_plugin.go b/x/wasm/keeper/handler_plugin.go index fb31af776..be608ed5c 100644 --- a/x/wasm/keeper/handler_plugin.go +++ b/x/wasm/keeper/handler_plugin.go @@ -4,6 +4,8 @@ import ( "errors" "fmt" + errorsmod "cosmossdk.io/errors" + wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cosmos/cosmos-sdk/baseapp" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -88,7 +90,7 @@ func (h SDKMessageHandler) handleSdkMessage(ctx sdk.Context, contractAddr sdk.Ad // make sure this account can send it for _, acct := range msg.GetSigners() { if !acct.Equals(contractAddr) { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "contract doesn't have permission") + return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "contract doesn't have permission") } } @@ -103,7 +105,7 @@ func (h SDKMessageHandler) handleSdkMessage(ctx sdk.Context, contractAddr sdk.Ad // proto messages and has registered all `Msg services`, then this // path should never be called, because all those Msgs should be // registered within the `msgServiceRouter` already. - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "can't route message %+v", msg) + return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "can't route message %+v", msg) } // MessageHandlerChain defines a chain of handlers that are called one by one until it can be handled. @@ -137,7 +139,7 @@ func (m MessageHandlerChain) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAd return events, data, err } } - return nil, nil, sdkerrors.Wrap(types.ErrUnknownMsg, "no handler found") + return nil, nil, errorsmod.Wrap(types.ErrUnknownMsg, "no handler found") } // IBCRawPacketHandler handels IBC.SendPacket messages which are published to an IBC channel. @@ -156,24 +158,27 @@ func (h IBCRawPacketHandler) DispatchMsg(ctx sdk.Context, _ sdk.AccAddress, cont return nil, nil, types.ErrUnknownMsg } if contractIBCPortID == "" { - return nil, nil, sdkerrors.Wrapf(types.ErrUnsupportedForContract, "ibc not supported") + return nil, nil, errorsmod.Wrapf(types.ErrUnsupportedForContract, "ibc not supported") } contractIBCChannelID := msg.IBC.SendPacket.ChannelID if contractIBCChannelID == "" { - return nil, nil, sdkerrors.Wrapf(types.ErrEmpty, "ibc channel") + return nil, nil, errorsmod.Wrapf(types.ErrEmpty, "ibc channel") } channelCap, ok := h.capabilityKeeper.GetCapability(ctx, host.ChannelCapabilityPath(contractIBCPortID, contractIBCChannelID)) if !ok { - return nil, nil, sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") + return nil, nil, errorsmod.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") } seq, err := h.channelKeeper.SendPacket(ctx, channelCap, contractIBCPortID, contractIBCChannelID, ConvertWasmIBCTimeoutHeightToCosmosHeight(msg.IBC.SendPacket.Timeout.Block), msg.IBC.SendPacket.Timeout.Timestamp, msg.IBC.SendPacket.Data) + if err != nil { + return nil, nil, errorsmod.Wrap(err, "channel") + } moduleLogger(ctx).Debug("ibc packet set", "seq", seq) resp := &types.MsgIBCSendResponse{Sequence: seq} val, err := resp.Marshal() if err != nil { - return nil, nil, sdkerrors.Wrap(err, "failed to marshal IBC send response") + return nil, nil, errorsmod.Wrap(err, "failed to marshal IBC send response") } return nil, [][]byte{val}, nil @@ -201,10 +206,10 @@ func NewBurnCoinMessageHandler(burner types.Burner) MessageHandlerFunc { return nil, nil, types.ErrEmpty.Wrap("amount") } if err := burner.SendCoinsFromAccountToModule(ctx, contractAddr, types.ModuleName, coins); err != nil { - return nil, nil, sdkerrors.Wrap(err, "transfer to module") + return nil, nil, errorsmod.Wrap(err, "transfer to module") } if err := burner.BurnCoins(ctx, types.ModuleName, coins); err != nil { - return nil, nil, sdkerrors.Wrap(err, "burn coins") + return nil, nil, errorsmod.Wrap(err, "burn coins") } moduleLogger(ctx).Info("Burned", "amount", coins) return nil, nil, nil diff --git a/x/wasm/keeper/handler_plugin_encoders.go b/x/wasm/keeper/handler_plugin_encoders.go index f18b988b5..6ad1cedb4 100644 --- a/x/wasm/keeper/handler_plugin_encoders.go +++ b/x/wasm/keeper/handler_plugin_encoders.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" + errorsmod "cosmossdk.io/errors" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" wasmvmtypes "github.com/CosmWasm/wasmvm/types" @@ -104,12 +105,12 @@ func (e MessageEncoders) Encode(ctx sdk.Context, contractAddr sdk.AccAddress, co case msg.Gov != nil: return EncodeGovMsg(contractAddr, msg.Gov) } - return nil, sdkerrors.Wrap(types.ErrUnknownMsg, "unknown variant of Wasm") + return nil, errorsmod.Wrap(types.ErrUnknownMsg, "unknown variant of Wasm") } func EncodeBankMsg(sender sdk.AccAddress, msg *wasmvmtypes.BankMsg) ([]sdk.Msg, error) { if msg.Send == nil { - return nil, sdkerrors.Wrap(types.ErrUnknownMsg, "unknown variant of Bank") + return nil, errorsmod.Wrap(types.ErrUnknownMsg, "unknown variant of Bank") } if len(msg.Send.Amount) == 0 { return nil, nil @@ -127,7 +128,7 @@ func EncodeBankMsg(sender sdk.AccAddress, msg *wasmvmtypes.BankMsg) ([]sdk.Msg, } func NoCustomMsg(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error) { - return nil, sdkerrors.Wrap(types.ErrUnknownMsg, "custom variant not supported") + return nil, errorsmod.Wrap(types.ErrUnknownMsg, "custom variant not supported") } func EncodeDistributionMsg(sender sdk.AccAddress, msg *wasmvmtypes.DistributionMsg) ([]sdk.Msg, error) { @@ -145,7 +146,7 @@ func EncodeDistributionMsg(sender sdk.AccAddress, msg *wasmvmtypes.DistributionM } return []sdk.Msg{&withdrawMsg}, nil default: - return nil, sdkerrors.Wrap(types.ErrUnknownMsg, "unknown variant of Distribution") + return nil, errorsmod.Wrap(types.ErrUnknownMsg, "unknown variant of Distribution") } } @@ -187,7 +188,7 @@ func EncodeStakingMsg(sender sdk.AccAddress, msg *wasmvmtypes.StakingMsg) ([]sdk } return []sdk.Msg{&sdkMsg}, nil default: - return nil, sdkerrors.Wrap(types.ErrUnknownMsg, "unknown variant of Staking") + return nil, errorsmod.Wrap(types.ErrUnknownMsg, "unknown variant of Staking") } } @@ -199,10 +200,10 @@ func EncodeStargateMsg(unpacker codectypes.AnyUnpacker) StargateEncoder { } var sdkMsg sdk.Msg if err := unpacker.UnpackAny(&any, &sdkMsg); err != nil { - return nil, sdkerrors.Wrap(types.ErrInvalidMsg, fmt.Sprintf("Cannot unpack proto message with type URL: %s", msg.TypeURL)) + return nil, errorsmod.Wrap(types.ErrInvalidMsg, fmt.Sprintf("Cannot unpack proto message with type URL: %s", msg.TypeURL)) } if err := codectypes.UnpackInterfaces(sdkMsg, unpacker); err != nil { - return nil, sdkerrors.Wrap(types.ErrInvalidMsg, fmt.Sprintf("UnpackInterfaces inside msg: %s", err)) + return nil, errorsmod.Wrap(types.ErrInvalidMsg, fmt.Sprintf("UnpackInterfaces inside msg: %s", err)) } return []sdk.Msg{sdkMsg}, nil } @@ -278,7 +279,7 @@ func EncodeWasmMsg(sender sdk.AccAddress, msg *wasmvmtypes.WasmMsg) ([]sdk.Msg, } return []sdk.Msg{&sdkMsg}, nil default: - return nil, sdkerrors.Wrap(types.ErrUnknownMsg, "unknown variant of Wasm") + return nil, errorsmod.Wrap(types.ErrUnknownMsg, "unknown variant of Wasm") } } @@ -294,7 +295,7 @@ func EncodeIBCMsg(portSource types.ICS20TransferPortSource) func(ctx sdk.Context case msg.Transfer != nil: amount, err := ConvertWasmCoinToSdkCoin(msg.Transfer.Amount) if err != nil { - return nil, sdkerrors.Wrap(err, "amount") + return nil, errorsmod.Wrap(err, "amount") } msg := &ibctransfertypes.MsgTransfer{ SourcePort: portSource.GetPort(ctx), @@ -307,7 +308,7 @@ func EncodeIBCMsg(portSource types.ICS20TransferPortSource) func(ctx sdk.Context } return []sdk.Msg{msg}, nil default: - return nil, sdkerrors.Wrap(types.ErrUnknownMsg, "unknown variant of IBC") + return nil, errorsmod.Wrap(types.ErrUnknownMsg, "unknown variant of IBC") } } } @@ -317,7 +318,7 @@ func EncodeGovMsg(sender sdk.AccAddress, msg *wasmvmtypes.GovMsg) ([]sdk.Msg, er case msg.Vote != nil: voteOption, err := convertVoteOption(msg.Vote.Vote) if err != nil { - return nil, sdkerrors.Wrap(err, "vote option") + return nil, errorsmod.Wrap(err, "vote option") } m := v1.NewMsgVote(sender, msg.Vote.ProposalId, voteOption, "") return []sdk.Msg{m}, nil @@ -326,11 +327,11 @@ func EncodeGovMsg(sender sdk.AccAddress, msg *wasmvmtypes.GovMsg) ([]sdk.Msg, er for i, v := range msg.VoteWeighted.Options { weight, err := sdk.NewDecFromStr(v.Weight) if err != nil { - return nil, sdkerrors.Wrapf(err, "weight for vote %d", i+1) + return nil, errorsmod.Wrapf(err, "weight for vote %d", i+1) } voteOption, err := convertVoteOption(v.Option) if err != nil { - return nil, sdkerrors.Wrap(err, "vote option") + return nil, errorsmod.Wrap(err, "vote option") } opts[i] = &v1.WeightedVoteOption{Option: voteOption, Weight: weight.String()} } @@ -384,7 +385,7 @@ func ConvertWasmCoinsToSdkCoins(coins []wasmvmtypes.Coin) (sdk.Coins, error) { func ConvertWasmCoinToSdkCoin(coin wasmvmtypes.Coin) (sdk.Coin, error) { amount, ok := sdk.NewIntFromString(coin.Amount) if !ok { - return sdk.Coin{}, sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, coin.Amount+coin.Denom) + return sdk.Coin{}, errorsmod.Wrap(sdkerrors.ErrInvalidCoins, coin.Amount+coin.Denom) } r := sdk.Coin{ Denom: coin.Denom, diff --git a/x/wasm/keeper/ibc.go b/x/wasm/keeper/ibc.go index a102b9805..faf06d5aa 100644 --- a/x/wasm/keeper/ibc.go +++ b/x/wasm/keeper/ibc.go @@ -3,8 +3,8 @@ package keeper import ( "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -39,7 +39,7 @@ func PortIDForContract(addr sdk.AccAddress) string { func ContractFromPortID(portID string) (sdk.AccAddress, error) { if !strings.HasPrefix(portID, portIDPrefix) { - return nil, sdkerrors.Wrapf(types.ErrInvalid, "without prefix") + return nil, errorsmod.Wrapf(types.ErrInvalid, "without prefix") } return sdk.AccAddressFromBech32(portID[len(portIDPrefix):]) } diff --git a/x/wasm/keeper/keeper.go b/x/wasm/keeper/keeper.go index c1ec2cb6e..a905daaee 100644 --- a/x/wasm/keeper/keeper.go +++ b/x/wasm/keeper/keeper.go @@ -12,6 +12,7 @@ import ( "strings" "time" + errorsmod "cosmossdk.io/errors" storetypes "github.com/cosmos/cosmos-sdk/store/types" wasmvm "github.com/CosmWasm/wasmvm" @@ -130,7 +131,7 @@ func (k Keeper) SetParams(ctx sdk.Context, ps types.Params) { func (k Keeper) create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, instantiateAccess *types.AccessConfig, authZ AuthorizationPolicy) (codeID uint64, checksum []byte, err error) { if creator == nil { - return 0, checksum, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "cannot be nil") + return 0, checksum, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "cannot be nil") } // figure out proper instantiate access @@ -144,25 +145,25 @@ func (k Keeper) create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, } if !authZ.CanCreateCode(chainConfigs, creator, *instantiateAccess) { - return 0, checksum, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "can not create code") + return 0, checksum, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "can not create code") } if ioutils.IsGzip(wasmCode) { ctx.GasMeter().ConsumeGas(k.gasRegister.UncompressCosts(len(wasmCode)), "Uncompress gzip bytecode") wasmCode, err = ioutils.Uncompress(wasmCode, uint64(types.MaxWasmSize)) if err != nil { - return 0, checksum, sdkerrors.Wrap(types.ErrCreateFailed, err.Error()) + return 0, checksum, errorsmod.Wrap(types.ErrCreateFailed, err.Error()) } } ctx.GasMeter().ConsumeGas(k.gasRegister.CompileCosts(len(wasmCode)), "Compiling wasm bytecode") checksum, err = k.wasmVM.Create(wasmCode) if err != nil { - return 0, checksum, sdkerrors.Wrap(types.ErrCreateFailed, err.Error()) + return 0, checksum, errorsmod.Wrap(types.ErrCreateFailed, err.Error()) } report, err := k.wasmVM.AnalyzeCode(checksum) if err != nil { - return 0, checksum, sdkerrors.Wrap(types.ErrCreateFailed, err.Error()) + return 0, checksum, errorsmod.Wrap(types.ErrCreateFailed, err.Error()) } codeID = k.autoIncrementID(ctx, types.KeyLastCodeID) k.Logger(ctx).Debug("storing new contract", "capabilities", report.RequiredCapabilities, "code_id", codeID) @@ -193,21 +194,21 @@ func (k Keeper) importCode(ctx sdk.Context, codeID uint64, codeInfo types.CodeIn var err error wasmCode, err = ioutils.Uncompress(wasmCode, uint64(types.MaxWasmSize)) if err != nil { - return sdkerrors.Wrap(types.ErrCreateFailed, err.Error()) + return errorsmod.Wrap(types.ErrCreateFailed, err.Error()) } } newCodeHash, err := k.wasmVM.Create(wasmCode) if err != nil { - return sdkerrors.Wrap(types.ErrCreateFailed, err.Error()) + return errorsmod.Wrap(types.ErrCreateFailed, err.Error()) } if !bytes.Equal(codeInfo.CodeHash, newCodeHash) { - return sdkerrors.Wrap(types.ErrInvalid, "code hashes not same") + return errorsmod.Wrap(types.ErrInvalid, "code hashes not same") } store := ctx.KVStore(k.storeKey) key := types.GetCodeKey(codeID) if store.Has(key) { - return sdkerrors.Wrapf(types.ErrDuplicate, "duplicate code: %d", codeID) + return errorsmod.Wrapf(types.ErrDuplicate, "duplicate code: %d", codeID) } // 0x01 | codeID (uint64) -> ContractInfo store.Set(key, k.cdc.MustMarshal(&codeInfo)) @@ -234,10 +235,10 @@ func (k Keeper) instantiate( codeInfo := k.GetCodeInfo(ctx, codeID) if codeInfo == nil { - return nil, nil, sdkerrors.Wrap(types.ErrNotFound, "code") + return nil, nil, errorsmod.Wrap(types.ErrNotFound, "code") } if !authPolicy.CanInstantiateContract(codeInfo.InstantiateConfig, creator) { - return nil, nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "can not instantiate") + return nil, nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "can not instantiate") } contractAddress := addressGenerator(ctx, codeID, codeInfo.CodeHash) @@ -267,7 +268,7 @@ func (k Keeper) instantiate( // also handle balance to not open cases where these accounts are abused and become liquid switch handled, err := k.accountPruner.CleanupExistingAccount(ctx, existingAcct); { case err != nil: - return nil, nil, sdkerrors.Wrap(err, "prune balance") + return nil, nil, errorsmod.Wrap(err, "prune balance") case !handled: return nil, nil, types.ErrAccountExists.Wrap("address is claimed by external account") } @@ -301,7 +302,7 @@ func (k Keeper) instantiate( res, gasUsed, err := k.wasmVM.Instantiate(codeInfo.CodeHash, env, info, initMsg, prefixStore, cosmwasmAPI, querier, k.gasMeter(ctx), gas, costJSONDeserialization) k.consumeRuntimeGas(ctx, gasUsed) if err != nil { - return nil, nil, sdkerrors.Wrap(types.ErrInstantiateFailed, err.Error()) + return nil, nil, errorsmod.Wrap(types.ErrInstantiateFailed, err.Error()) } // persist instance first @@ -311,7 +312,7 @@ func (k Keeper) instantiate( // check for IBC flag report, err := k.wasmVM.AnalyzeCode(codeInfo.CodeHash) if err != nil { - return nil, nil, sdkerrors.Wrap(types.ErrInstantiateFailed, err.Error()) + return nil, nil, errorsmod.Wrap(types.ErrInstantiateFailed, err.Error()) } if report.HasIBCEntryPoints { // register IBC port @@ -337,7 +338,7 @@ func (k Keeper) instantiate( data, err := k.handleContractResponse(ctx, contractAddress, contractInfo.IBCPortID, res.Messages, res.Attributes, res.Data, res.Events) if err != nil { - return nil, nil, sdkerrors.Wrap(err, "dispatch") + return nil, nil, errorsmod.Wrap(err, "dispatch") } return contractAddress, data, nil @@ -370,7 +371,7 @@ func (k Keeper) execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller res, gasUsed, execErr := k.wasmVM.Execute(codeInfo.CodeHash, env, info, msg, prefixStore, cosmwasmAPI, querier, k.gasMeter(ctx), gas, costJSONDeserialization) k.consumeRuntimeGas(ctx, gasUsed) if execErr != nil { - return nil, sdkerrors.Wrap(types.ErrExecuteFailed, execErr.Error()) + return nil, errorsmod.Wrap(types.ErrExecuteFailed, execErr.Error()) } ctx.EventManager().EmitEvent(sdk.NewEvent( @@ -380,7 +381,7 @@ func (k Keeper) execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller data, err := k.handleContractResponse(ctx, contractAddress, contractInfo.IBCPortID, res.Messages, res.Attributes, res.Data, res.Events) if err != nil { - return nil, sdkerrors.Wrap(err, "dispatch") + return nil, errorsmod.Wrap(err, "dispatch") } return data, nil @@ -393,28 +394,28 @@ func (k Keeper) migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller contractInfo := k.GetContractInfo(ctx, contractAddress) if contractInfo == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "unknown contract") + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "unknown contract") } if !authZ.CanModifyContract(contractInfo.AdminAddr(), caller) { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "can not migrate") + return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "can not migrate") } newCodeInfo := k.GetCodeInfo(ctx, newCodeID) if newCodeInfo == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "unknown code") + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "unknown code") } if !authZ.CanInstantiateContract(newCodeInfo.InstantiateConfig, caller) { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "to use new code") + return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "to use new code") } // check for IBC flag switch report, err := k.wasmVM.AnalyzeCode(newCodeInfo.CodeHash); { case err != nil: - return nil, sdkerrors.Wrap(types.ErrMigrationFailed, err.Error()) + return nil, errorsmod.Wrap(types.ErrMigrationFailed, err.Error()) case !report.HasIBCEntryPoints && contractInfo.IBCPortID != "": // prevent update to non ibc contract - return nil, sdkerrors.Wrap(types.ErrMigrationFailed, "requires ibc callbacks") + return nil, errorsmod.Wrap(types.ErrMigrationFailed, "requires ibc callbacks") case report.HasIBCEntryPoints && contractInfo.IBCPortID == "": // add ibc port ibcPort, err := k.ensureIbcPort(ctx, contractAddress) @@ -435,7 +436,7 @@ func (k Keeper) migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller res, gasUsed, err := k.wasmVM.Migrate(newCodeInfo.CodeHash, env, msg, &prefixStore, cosmwasmAPI, &querier, k.gasMeter(ctx), gas, costJSONDeserialization) k.consumeRuntimeGas(ctx, gasUsed) if err != nil { - return nil, sdkerrors.Wrap(types.ErrMigrationFailed, err.Error()) + return nil, errorsmod.Wrap(types.ErrMigrationFailed, err.Error()) } // delete old secondary index entry k.removeFromContractCodeSecondaryIndex(ctx, contractAddress, k.getLastContractHistoryEntry(ctx, contractAddress)) @@ -453,7 +454,7 @@ func (k Keeper) migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller data, err := k.handleContractResponse(ctx, contractAddress, contractInfo.IBCPortID, res.Messages, res.Attributes, res.Data, res.Events) if err != nil { - return nil, sdkerrors.Wrap(err, "dispatch") + return nil, errorsmod.Wrap(err, "dispatch") } return data, nil @@ -480,7 +481,7 @@ func (k Keeper) Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte res, gasUsed, execErr := k.wasmVM.Sudo(codeInfo.CodeHash, env, msg, prefixStore, cosmwasmAPI, querier, k.gasMeter(ctx), gas, costJSONDeserialization) k.consumeRuntimeGas(ctx, gasUsed) if execErr != nil { - return nil, sdkerrors.Wrap(types.ErrExecuteFailed, execErr.Error()) + return nil, errorsmod.Wrap(types.ErrExecuteFailed, execErr.Error()) } ctx.EventManager().EmitEvent(sdk.NewEvent( @@ -490,7 +491,7 @@ func (k Keeper) Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte data, err := k.handleContractResponse(ctx, contractAddress, contractInfo.IBCPortID, res.Messages, res.Attributes, res.Data, res.Events) if err != nil { - return nil, sdkerrors.Wrap(err, "dispatch") + return nil, errorsmod.Wrap(err, "dispatch") } return data, nil @@ -516,7 +517,7 @@ func (k Keeper) reply(ctx sdk.Context, contractAddress sdk.AccAddress, reply was res, gasUsed, execErr := k.wasmVM.Reply(codeInfo.CodeHash, env, reply, prefixStore, cosmwasmAPI, querier, k.gasMeter(ctx), gas, costJSONDeserialization) k.consumeRuntimeGas(ctx, gasUsed) if execErr != nil { - return nil, sdkerrors.Wrap(types.ErrExecuteFailed, execErr.Error()) + return nil, errorsmod.Wrap(types.ErrExecuteFailed, execErr.Error()) } ctx.EventManager().EmitEvent(sdk.NewEvent( @@ -526,7 +527,7 @@ func (k Keeper) reply(ctx sdk.Context, contractAddress sdk.AccAddress, reply was data, err := k.handleContractResponse(ctx, contractAddress, contractInfo.IBCPortID, res.Messages, res.Attributes, res.Data, res.Events) if err != nil { - return nil, sdkerrors.Wrap(err, "dispatch") + return nil, errorsmod.Wrap(err, "dispatch") } return data, nil @@ -577,10 +578,10 @@ func (k Keeper) IterateContractsByCode(ctx sdk.Context, codeID uint64, cb func(a func (k Keeper) setContractAdmin(ctx sdk.Context, contractAddress, caller, newAdmin sdk.AccAddress, authZ AuthorizationPolicy) error { contractInfo := k.GetContractInfo(ctx, contractAddress) if contractInfo == nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "unknown contract") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "unknown contract") } if !authZ.CanModifyContract(contractInfo.AdminAddr(), caller) { - return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "can not modify contract") + return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "can not modify contract") } newAdminStr := newAdmin.String() contractInfo.Admin = newAdminStr @@ -667,7 +668,7 @@ func (k Keeper) QuerySmart(ctx sdk.Context, contractAddr sdk.AccAddress, req []b queryResult, gasUsed, qErr := k.wasmVM.Query(codeInfo.CodeHash, env, req, prefixStore, cosmwasmAPI, querier, k.gasMeter(ctx), k.runtimeGasForContract(ctx), costJSONDeserialization) k.consumeRuntimeGas(ctx, gasUsed) if qErr != nil { - return nil, sdkerrors.Wrap(types.ErrQueryFailed, qErr.Error()) + return nil, errorsmod.Wrap(types.ErrQueryFailed, qErr.Error()) } return queryResult, nil } @@ -712,14 +713,14 @@ func (k Keeper) contractInstance(ctx sdk.Context, contractAddress sdk.AccAddress contractBz := store.Get(types.GetContractAddressKey(contractAddress)) if contractBz == nil { - return types.ContractInfo{}, types.CodeInfo{}, prefix.Store{}, sdkerrors.Wrap(types.ErrNotFound, "contract") + return types.ContractInfo{}, types.CodeInfo{}, prefix.Store{}, errorsmod.Wrap(types.ErrNotFound, "contract") } var contractInfo types.ContractInfo k.cdc.MustUnmarshal(contractBz, &contractInfo) codeInfoBz := store.Get(types.GetCodeKey(contractInfo.CodeID)) if codeInfoBz == nil { - return contractInfo, types.CodeInfo{}, prefix.Store{}, sdkerrors.Wrap(types.ErrNotFound, "code info") + return contractInfo, types.CodeInfo{}, prefix.Store{}, errorsmod.Wrap(types.ErrNotFound, "code info") } var codeInfo types.CodeInfo k.cdc.MustUnmarshal(codeInfoBz, &codeInfo) @@ -788,7 +789,7 @@ func (k Keeper) importContractState(ctx sdk.Context, contractAddress sdk.AccAddr model.Value = []byte{} } if prefixStore.Has(model.Key) { - return sdkerrors.Wrapf(types.ErrDuplicate, "duplicate key: %x", model.Key) + return errorsmod.Wrapf(types.ErrDuplicate, "duplicate key: %x", model.Key) } prefixStore.Set(model.Key, model.Value) } @@ -841,11 +842,11 @@ func (k Keeper) GetByteCode(ctx sdk.Context, codeID uint64) ([]byte, error) { func (k Keeper) pinCode(ctx sdk.Context, codeID uint64) error { codeInfo := k.GetCodeInfo(ctx, codeID) if codeInfo == nil { - return sdkerrors.Wrap(types.ErrNotFound, "code info") + return errorsmod.Wrap(types.ErrNotFound, "code info") } if err := k.wasmVM.Pin(codeInfo.CodeHash); err != nil { - return sdkerrors.Wrap(types.ErrPinContractFailed, err.Error()) + return errorsmod.Wrap(types.ErrPinContractFailed, err.Error()) } store := ctx.KVStore(k.storeKey) // store 1 byte to not run into `nil` debugging issues @@ -862,10 +863,10 @@ func (k Keeper) pinCode(ctx sdk.Context, codeID uint64) error { func (k Keeper) unpinCode(ctx sdk.Context, codeID uint64) error { codeInfo := k.GetCodeInfo(ctx, codeID) if codeInfo == nil { - return sdkerrors.Wrap(types.ErrNotFound, "code info") + return errorsmod.Wrap(types.ErrNotFound, "code info") } if err := k.wasmVM.Unpin(codeInfo.CodeHash); err != nil { - return sdkerrors.Wrap(types.ErrUnpinContractFailed, err.Error()) + return errorsmod.Wrap(types.ErrUnpinContractFailed, err.Error()) } store := ctx.KVStore(k.storeKey) @@ -893,10 +894,10 @@ func (k Keeper) InitializePinnedCodes(ctx sdk.Context) error { for ; iter.Valid(); iter.Next() { codeInfo := k.GetCodeInfo(ctx, types.ParsePinnedCodeIndex(iter.Key())) if codeInfo == nil { - return sdkerrors.Wrap(types.ErrNotFound, "code info") + return errorsmod.Wrap(types.ErrNotFound, "code info") } if err := k.wasmVM.Pin(codeInfo.CodeHash); err != nil { - return sdkerrors.Wrap(types.ErrPinContractFailed, err.Error()) + return errorsmod.Wrap(types.ErrPinContractFailed, err.Error()) } } return nil @@ -906,7 +907,7 @@ func (k Keeper) InitializePinnedCodes(ctx sdk.Context) error { func (k Keeper) setContractInfoExtension(ctx sdk.Context, contractAddr sdk.AccAddress, ext types.ContractInfoExtension) error { info := k.GetContractInfo(ctx, contractAddr) if info == nil { - return sdkerrors.Wrap(types.ErrNotFound, "contract info") + return errorsmod.Wrap(types.ErrNotFound, "contract info") } if err := info.SetExtension(ext); err != nil { return err @@ -919,11 +920,11 @@ func (k Keeper) setContractInfoExtension(ctx sdk.Context, contractAddr sdk.AccAd func (k Keeper) setAccessConfig(ctx sdk.Context, codeID uint64, caller sdk.AccAddress, newConfig types.AccessConfig, authz AuthorizationPolicy) error { info := k.GetCodeInfo(ctx, codeID) if info == nil { - return sdkerrors.Wrap(types.ErrNotFound, "code info") + return errorsmod.Wrap(types.ErrNotFound, "code info") } isSubset := newConfig.Permission.IsSubset(k.getInstantiateAccessConfig(ctx)) if !authz.CanModifyCodeAccessConfig(sdk.MustAccAddressFromBech32(info.Creator), caller, isSubset) { - return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "can not modify code access config") + return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "can not modify code access config") } info.InstantiateConfig = newConfig @@ -1017,7 +1018,7 @@ func (k Keeper) PeekAutoIncrementID(ctx sdk.Context, lastIDKey []byte) uint64 { func (k Keeper) importAutoIncrementID(ctx sdk.Context, lastIDKey []byte, val uint64) error { store := ctx.KVStore(k.storeKey) if store.Has(lastIDKey) { - return sdkerrors.Wrapf(types.ErrDuplicate, "autoincrement id: %s", string(lastIDKey)) + return errorsmod.Wrapf(types.ErrDuplicate, "autoincrement id: %s", string(lastIDKey)) } bz := sdk.Uint64ToBigEndian(val) store.Set(lastIDKey, bz) @@ -1026,10 +1027,10 @@ func (k Keeper) importAutoIncrementID(ctx sdk.Context, lastIDKey []byte, val uin func (k Keeper) importContract(ctx sdk.Context, contractAddr sdk.AccAddress, c *types.ContractInfo, state []types.Model, entries []types.ContractCodeHistoryEntry) error { if !k.containsCodeInfo(ctx, c.CodeID) { - return sdkerrors.Wrapf(types.ErrNotFound, "code id: %d", c.CodeID) + return errorsmod.Wrapf(types.ErrNotFound, "code id: %d", c.CodeID) } if k.HasContractInfo(ctx, contractAddr) { - return sdkerrors.Wrapf(types.ErrDuplicate, "contract: %s", contractAddr) + return errorsmod.Wrapf(types.ErrDuplicate, "contract: %s", contractAddr) } creatorAddress, err := sdk.AccAddressFromBech32(c.Creator) @@ -1108,7 +1109,7 @@ func (c BankCoinTransferrer) TransferCoins(parentCtx sdk.Context, fromAddr sdk.A return err } if c.keeper.BlockedAddr(toAddr) { - return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", toAddr.String()) + return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", toAddr.String()) } sdkerr := c.keeper.SendCoins(ctx, fromAddr, toAddr, amount) @@ -1153,10 +1154,10 @@ func (b VestingCoinBurner) CleanupExistingAccount(ctx sdk.Context, existingAcc a coinsToBurn = append(coinsToBurn, b.bank.GetBalance(ctx, existingAcc.GetAddress(), orig.Denom)) } if err := b.bank.SendCoinsFromAccountToModule(ctx, existingAcc.GetAddress(), types.ModuleName, coinsToBurn); err != nil { - return false, sdkerrors.Wrap(err, "prune account balance") + return false, errorsmod.Wrap(err, "prune account balance") } if err := b.bank.BurnCoins(ctx, types.ModuleName, coinsToBurn); err != nil { - return false, sdkerrors.Wrap(err, "burn account balance") + return false, errorsmod.Wrap(err, "burn account balance") } return true, nil } @@ -1181,7 +1182,7 @@ func (h DefaultWasmVMContractResponseHandler) Handle(ctx sdk.Context, contractAd result := origRspData switch rsp, err := h.md.DispatchSubmessages(ctx, contractAddr, ibcPort, messages); { case err != nil: - return nil, sdkerrors.Wrap(err, "submessages") + return nil, errorsmod.Wrap(err, "submessages") case rsp != nil: result = rsp } diff --git a/x/wasm/keeper/msg_dispatcher.go b/x/wasm/keeper/msg_dispatcher.go index 11eb8aa0a..661802259 100644 --- a/x/wasm/keeper/msg_dispatcher.go +++ b/x/wasm/keeper/msg_dispatcher.go @@ -5,6 +5,7 @@ import ( "sort" "strings" + errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -63,7 +64,7 @@ func (d MessageDispatcher) dispatchMsgWithGasLimit(ctx sdk.Context, contractAddr panic(r) } ctx.GasMeter().ConsumeGas(gasLimit, "Sub-Message OutOfGas panic") - err = sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "SubMsg hit gas limit") + err = errorsmod.Wrap(sdkerrors.ErrOutOfGas, "SubMsg hit gas limit") } }() events, data, err = d.messenger.DispatchMsg(subCtx, contractAddr, ibcPort, msg) @@ -83,7 +84,7 @@ func (d MessageDispatcher) DispatchSubmessages(ctx sdk.Context, contractAddr sdk switch msg.ReplyOn { case wasmvmtypes.ReplySuccess, wasmvmtypes.ReplyError, wasmvmtypes.ReplyAlways, wasmvmtypes.ReplyNever: default: - return nil, sdkerrors.Wrap(types.ErrInvalid, "replyOn value") + return nil, errorsmod.Wrap(types.ErrInvalid, "replyOn value") } // first, we build a sub-context which we can use inside the submessages subCtx, commit := ctx.CacheContext() @@ -163,7 +164,7 @@ func (d MessageDispatcher) DispatchSubmessages(ctx sdk.Context, contractAddr sdk rspData, err := d.keeper.reply(ctx, contractAddr, reply) switch { case err != nil: - return nil, sdkerrors.Wrap(err, "reply") + return nil, errorsmod.Wrap(err, "reply") case rspData != nil: rsp = rspData } @@ -184,7 +185,7 @@ func redactError(err error) error { // sdk/11 is out of gas // sdk/5 is insufficient funds (on bank send) // (we can theoretically redact less in the future, but this is a first step to safety) - codespace, code, _ := sdkerrors.ABCIInfo(err, false) + codespace, code, _ := errorsmod.ABCIInfo(err, false) return fmt.Errorf("codespace: %s, code: %d", codespace, code) } diff --git a/x/wasm/keeper/msg_server.go b/x/wasm/keeper/msg_server.go index d0383db69..fb311472d 100644 --- a/x/wasm/keeper/msg_server.go +++ b/x/wasm/keeper/msg_server.go @@ -3,8 +3,8 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -26,7 +26,7 @@ func (m msgServer) StoreCode(goCtx context.Context, msg *types.MsgStoreCode) (*t ctx := sdk.UnwrapSDKContext(goCtx) senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) if err != nil { - return nil, sdkerrors.Wrap(err, "sender") + return nil, errorsmod.Wrap(err, "sender") } ctx.EventManager().EmitEvent(sdk.NewEvent( @@ -55,12 +55,12 @@ func (m msgServer) InstantiateContract(goCtx context.Context, msg *types.MsgInst senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) if err != nil { - return nil, sdkerrors.Wrap(err, "sender") + return nil, errorsmod.Wrap(err, "sender") } var adminAddr sdk.AccAddress if msg.Admin != "" { if adminAddr, err = sdk.AccAddressFromBech32(msg.Admin); err != nil { - return nil, sdkerrors.Wrap(err, "admin") + return nil, errorsmod.Wrap(err, "admin") } } @@ -90,12 +90,12 @@ func (m msgServer) InstantiateContract2(goCtx context.Context, msg *types.MsgIns senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) if err != nil { - return nil, sdkerrors.Wrap(err, "sender") + return nil, errorsmod.Wrap(err, "sender") } var adminAddr sdk.AccAddress if msg.Admin != "" { if adminAddr, err = sdk.AccAddressFromBech32(msg.Admin); err != nil { - return nil, sdkerrors.Wrap(err, "admin") + return nil, errorsmod.Wrap(err, "admin") } } @@ -123,11 +123,11 @@ func (m msgServer) ExecuteContract(goCtx context.Context, msg *types.MsgExecuteC ctx := sdk.UnwrapSDKContext(goCtx) senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) if err != nil { - return nil, sdkerrors.Wrap(err, "sender") + return nil, errorsmod.Wrap(err, "sender") } contractAddr, err := sdk.AccAddressFromBech32(msg.Contract) if err != nil { - return nil, sdkerrors.Wrap(err, "contract") + return nil, errorsmod.Wrap(err, "contract") } ctx.EventManager().EmitEvent(sdk.NewEvent( @@ -154,11 +154,11 @@ func (m msgServer) MigrateContract(goCtx context.Context, msg *types.MsgMigrateC ctx := sdk.UnwrapSDKContext(goCtx) senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) if err != nil { - return nil, sdkerrors.Wrap(err, "sender") + return nil, errorsmod.Wrap(err, "sender") } contractAddr, err := sdk.AccAddressFromBech32(msg.Contract) if err != nil { - return nil, sdkerrors.Wrap(err, "contract") + return nil, errorsmod.Wrap(err, "contract") } ctx.EventManager().EmitEvent(sdk.NewEvent( @@ -185,15 +185,15 @@ func (m msgServer) UpdateAdmin(goCtx context.Context, msg *types.MsgUpdateAdmin) ctx := sdk.UnwrapSDKContext(goCtx) senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) if err != nil { - return nil, sdkerrors.Wrap(err, "sender") + return nil, errorsmod.Wrap(err, "sender") } contractAddr, err := sdk.AccAddressFromBech32(msg.Contract) if err != nil { - return nil, sdkerrors.Wrap(err, "contract") + return nil, errorsmod.Wrap(err, "contract") } newAdminAddr, err := sdk.AccAddressFromBech32(msg.NewAdmin) if err != nil { - return nil, sdkerrors.Wrap(err, "new admin") + return nil, errorsmod.Wrap(err, "new admin") } ctx.EventManager().EmitEvent(sdk.NewEvent( @@ -217,11 +217,11 @@ func (m msgServer) ClearAdmin(goCtx context.Context, msg *types.MsgClearAdmin) ( ctx := sdk.UnwrapSDKContext(goCtx) senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) if err != nil { - return nil, sdkerrors.Wrap(err, "sender") + return nil, errorsmod.Wrap(err, "sender") } contractAddr, err := sdk.AccAddressFromBech32(msg.Contract) if err != nil { - return nil, sdkerrors.Wrap(err, "contract") + return nil, errorsmod.Wrap(err, "contract") } ctx.EventManager().EmitEvent(sdk.NewEvent( diff --git a/x/wasm/keeper/proposal_handler.go b/x/wasm/keeper/proposal_handler.go index bf99a4fad..46d6b718c 100644 --- a/x/wasm/keeper/proposal_handler.go +++ b/x/wasm/keeper/proposal_handler.go @@ -5,6 +5,8 @@ import ( "encoding/hex" "fmt" + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -25,10 +27,10 @@ func NewWasmProposalHandlerX(k types.ContractOpsKeeper, enabledProposalTypes []t } return func(ctx sdk.Context, content v1beta1.Content) error { if content == nil { - return sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "content must not be empty") + return errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "content must not be empty") } if _, ok := enabledTypes[content.ProposalType()]; !ok { - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unsupported wasm proposal content type: %q", content.ProposalType()) + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unsupported wasm proposal content type: %q", content.ProposalType()) } switch c := content.(type) { case *types.StoreCodeProposal: @@ -56,7 +58,7 @@ func NewWasmProposalHandlerX(k types.ContractOpsKeeper, enabledProposalTypes []t case *types.StoreAndInstantiateContractProposal: return handleStoreAndInstantiateContractProposal(ctx, k, *c) default: - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized wasm proposal content type: %T", c) + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized wasm proposal content type: %T", c) } } } @@ -68,7 +70,7 @@ func handleStoreCodeProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) if err != nil { - return sdkerrors.Wrap(err, "run as address") + return errorsmod.Wrap(err, "run as address") } codeID, checksum, err := k.Create(ctx, runAsAddr, p.WASMByteCode, p.InstantiatePermission) if err != nil { @@ -92,12 +94,12 @@ func handleInstantiateProposal(ctx sdk.Context, k types.ContractOpsKeeper, p typ } runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) if err != nil { - return sdkerrors.Wrap(err, "run as address") + return errorsmod.Wrap(err, "run as address") } var adminAddr sdk.AccAddress if p.Admin != "" { if adminAddr, err = sdk.AccAddressFromBech32(p.Admin); err != nil { - return sdkerrors.Wrap(err, "admin") + return errorsmod.Wrap(err, "admin") } } @@ -122,14 +124,14 @@ func handleInstantiate2Proposal(ctx sdk.Context, k types.ContractOpsKeeper, p ty // Get runAsAddr as AccAddress runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) if err != nil { - return sdkerrors.Wrap(err, "run as address") + return errorsmod.Wrap(err, "run as address") } // Get admin address var adminAddr sdk.AccAddress if p.Admin != "" { if adminAddr, err = sdk.AccAddressFromBech32(p.Admin); err != nil { - return sdkerrors.Wrap(err, "admin") + return errorsmod.Wrap(err, "admin") } } @@ -151,12 +153,12 @@ func handleStoreAndInstantiateContractProposal(ctx sdk.Context, k types.Contract } runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) if err != nil { - return sdkerrors.Wrap(err, "run as address") + return errorsmod.Wrap(err, "run as address") } var adminAddr sdk.AccAddress if p.Admin != "" { if adminAddr, err = sdk.AccAddressFromBech32(p.Admin); err != nil { - return sdkerrors.Wrap(err, "admin") + return errorsmod.Wrap(err, "admin") } } @@ -166,7 +168,7 @@ func handleStoreAndInstantiateContractProposal(ctx sdk.Context, k types.Contract } if p.CodeHash != nil && !bytes.Equal(checksum, p.CodeHash) { - return sdkerrors.Wrap(fmt.Errorf("code-hash mismatch: %X, checksum: %X", p.CodeHash, checksum), "code-hash mismatch") + return errorsmod.Wrap(fmt.Errorf("code-hash mismatch: %X, checksum: %X", p.CodeHash, checksum), "code-hash mismatch") } if !p.UnpinCode { @@ -194,7 +196,7 @@ func handleMigrateProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.M contractAddr, err := sdk.AccAddressFromBech32(p.Contract) if err != nil { - return sdkerrors.Wrap(err, "contract") + return errorsmod.Wrap(err, "contract") } // runAs is not used if this is permissioned, so just put any valid address there (second contractAddr) @@ -217,7 +219,7 @@ func handleSudoProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.Sudo contractAddr, err := sdk.AccAddressFromBech32(p.Contract) if err != nil { - return sdkerrors.Wrap(err, "contract") + return errorsmod.Wrap(err, "contract") } data, err := k.Sudo(ctx, contractAddr, p.Msg) if err != nil { @@ -238,11 +240,11 @@ func handleExecuteProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.E contractAddr, err := sdk.AccAddressFromBech32(p.Contract) if err != nil { - return sdkerrors.Wrap(err, "contract") + return errorsmod.Wrap(err, "contract") } runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) if err != nil { - return sdkerrors.Wrap(err, "run as address") + return errorsmod.Wrap(err, "run as address") } data, err := k.Execute(ctx, contractAddr, runAsAddr, p.Msg, p.Funds) if err != nil { @@ -262,11 +264,11 @@ func handleUpdateAdminProposal(ctx sdk.Context, k types.ContractOpsKeeper, p typ } contractAddr, err := sdk.AccAddressFromBech32(p.Contract) if err != nil { - return sdkerrors.Wrap(err, "contract") + return errorsmod.Wrap(err, "contract") } newAdminAddr, err := sdk.AccAddressFromBech32(p.NewAdmin) if err != nil { - return sdkerrors.Wrap(err, "run as address") + return errorsmod.Wrap(err, "run as address") } return k.UpdateContractAdmin(ctx, contractAddr, nil, newAdminAddr) @@ -279,7 +281,7 @@ func handleClearAdminProposal(ctx sdk.Context, k types.ContractOpsKeeper, p type contractAddr, err := sdk.AccAddressFromBech32(p.Contract) if err != nil { - return sdkerrors.Wrap(err, "contract") + return errorsmod.Wrap(err, "contract") } if err := k.ClearContractAdmin(ctx, contractAddr, nil); err != nil { return err @@ -293,7 +295,7 @@ func handlePinCodesProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types. } for _, v := range p.CodeIDs { if err := k.PinCode(ctx, v); err != nil { - return sdkerrors.Wrapf(err, "code id: %d", v) + return errorsmod.Wrapf(err, "code id: %d", v) } } return nil @@ -305,7 +307,7 @@ func handleUnpinCodesProposal(ctx sdk.Context, k types.ContractOpsKeeper, p type } for _, v := range p.CodeIDs { if err := k.UnpinCode(ctx, v); err != nil { - return sdkerrors.Wrapf(err, "code id: %d", v) + return errorsmod.Wrapf(err, "code id: %d", v) } } return nil @@ -319,7 +321,7 @@ func handleUpdateInstantiateConfigProposal(ctx sdk.Context, k types.ContractOpsK var emptyCaller sdk.AccAddress for _, accessConfigUpdate := range p.AccessConfigUpdates { if err := k.SetAccessConfig(ctx, accessConfigUpdate.CodeID, emptyCaller, accessConfigUpdate.InstantiatePermission); err != nil { - return sdkerrors.Wrapf(err, "code id: %d", accessConfigUpdate.CodeID) + return errorsmod.Wrapf(err, "code id: %d", accessConfigUpdate.CodeID) } } return nil diff --git a/x/wasm/keeper/querier.go b/x/wasm/keeper/querier.go index fb33b4ca0..d0ee2727e 100644 --- a/x/wasm/keeper/querier.go +++ b/x/wasm/keeper/querier.go @@ -5,6 +5,7 @@ import ( "encoding/binary" "runtime/debug" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" storetypes "github.com/cosmos/cosmos-sdk/store/types" @@ -87,7 +88,7 @@ func (q grpcQuerier) ContractsByCode(c context.Context, req *types.QueryContract return nil, status.Error(codes.InvalidArgument, "empty request") } if req.CodeId == 0 { - return nil, sdkerrors.Wrap(types.ErrInvalid, "code id") + return nil, errorsmod.Wrap(types.ErrInvalid, "code id") } ctx := sdk.UnwrapSDKContext(c) r := make([]string, 0) @@ -177,7 +178,7 @@ func (q grpcQuerier) SmartContractState(c context.Context, req *types.QuerySmart if r := recover(); r != nil { switch rType := r.(type) { case sdk.ErrorOutOfGas: - err = sdkerrors.Wrapf(sdkerrors.ErrOutOfGas, + err = errorsmod.Wrapf(sdkerrors.ErrOutOfGas, "out of gas in location: %v; gasWanted: %d, gasUsed: %d", rType.Descriptor, ctx.GasMeter().Limit(), ctx.GasMeter().GasConsumed(), ) @@ -208,7 +209,7 @@ func (q grpcQuerier) Code(c context.Context, req *types.QueryCodeRequest) (*type return nil, status.Error(codes.InvalidArgument, "empty request") } if req.CodeId == 0 { - return nil, sdkerrors.Wrap(types.ErrInvalid, "code id") + return nil, errorsmod.Wrap(types.ErrInvalid, "code id") } rsp, err := queryCode(sdk.UnwrapSDKContext(c), req.CodeId, q.keeper) switch { @@ -280,7 +281,7 @@ func queryCode(ctx sdk.Context, codeID uint64, keeper types.ViewKeeper) (*types. code, err := keeper.GetByteCode(ctx, codeID) if err != nil { - return nil, sdkerrors.Wrap(err, "loading wasm code") + return nil, errorsmod.Wrap(err, "loading wasm code") } return &types.QueryCodeResponse{CodeInfoResponse: &info, Data: code}, nil diff --git a/x/wasm/keeper/query_plugins.go b/x/wasm/keeper/query_plugins.go index 954a2df13..8df268716 100644 --- a/x/wasm/keeper/query_plugins.go +++ b/x/wasm/keeper/query_plugins.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" + errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" @@ -168,7 +169,7 @@ func BankQuerier(bankKeeper types.BankViewKeeper) func(ctx sdk.Context, request if request.AllBalances != nil { addr, err := sdk.AccAddressFromBech32(request.AllBalances.Address) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, request.AllBalances.Address) + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, request.AllBalances.Address) } coins := bankKeeper.GetAllBalances(ctx, addr) res := wasmvmtypes.AllBalancesResponse{ @@ -179,7 +180,7 @@ func BankQuerier(bankKeeper types.BankViewKeeper) func(ctx sdk.Context, request if request.Balance != nil { addr, err := sdk.AccAddressFromBech32(request.Balance.Address) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, request.Balance.Address) + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, request.Balance.Address) } coin := bankKeeper.GetBalance(ctx, addr, request.Balance.Denom) res := wasmvmtypes.BalanceResponse{ @@ -369,7 +370,7 @@ func StakingQuerier(keeper types.StakingKeeper, distKeeper types.DistributionKee if request.AllDelegations != nil { delegator, err := sdk.AccAddressFromBech32(request.AllDelegations.Delegator) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, request.AllDelegations.Delegator) + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, request.AllDelegations.Delegator) } sdkDels := keeper.GetAllDelegatorDelegations(ctx, delegator) delegations, err := sdkToDelegations(ctx, keeper, sdkDels) @@ -384,11 +385,11 @@ func StakingQuerier(keeper types.StakingKeeper, distKeeper types.DistributionKee if request.Delegation != nil { delegator, err := sdk.AccAddressFromBech32(request.Delegation.Delegator) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, request.Delegation.Delegator) + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, request.Delegation.Delegator) } validator, err := sdk.ValAddressFromBech32(request.Delegation.Validator) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, request.Delegation.Validator) + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, request.Delegation.Validator) } var res wasmvmtypes.DelegationResponse @@ -412,18 +413,18 @@ func sdkToDelegations(ctx sdk.Context, keeper types.StakingKeeper, delegations [ for i, d := range delegations { delAddr, err := sdk.AccAddressFromBech32(d.DelegatorAddress) if err != nil { - return nil, sdkerrors.Wrap(err, "delegator address") + return nil, errorsmod.Wrap(err, "delegator address") } valAddr, err := sdk.ValAddressFromBech32(d.ValidatorAddress) if err != nil { - return nil, sdkerrors.Wrap(err, "validator address") + return nil, errorsmod.Wrap(err, "validator address") } // shares to amount logic comes from here: // https://github.com/cosmos/cosmos-sdk/blob/v0.38.3/x/staking/keeper/querier.go#L404 val, found := keeper.GetValidator(ctx, valAddr) if !found { - return nil, sdkerrors.Wrap(stakingtypes.ErrNoValidatorFound, "can't load validator for delegation") + return nil, errorsmod.Wrap(stakingtypes.ErrNoValidatorFound, "can't load validator for delegation") } amount := sdk.NewCoin(bondDenom, val.TokensFromShares(d.Shares).TruncateInt()) @@ -439,15 +440,15 @@ func sdkToDelegations(ctx sdk.Context, keeper types.StakingKeeper, delegations [ func sdkToFullDelegation(ctx sdk.Context, keeper types.StakingKeeper, distKeeper types.DistributionKeeper, delegation stakingtypes.Delegation) (*wasmvmtypes.FullDelegation, error) { delAddr, err := sdk.AccAddressFromBech32(delegation.DelegatorAddress) if err != nil { - return nil, sdkerrors.Wrap(err, "delegator address") + return nil, errorsmod.Wrap(err, "delegator address") } valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) if err != nil { - return nil, sdkerrors.Wrap(err, "validator address") + return nil, errorsmod.Wrap(err, "validator address") } val, found := keeper.GetValidator(ctx, valAddr) if !found { - return nil, sdkerrors.Wrap(stakingtypes.ErrNoValidatorFound, "can't load validator for delegation") + return nil, errorsmod.Wrap(stakingtypes.ErrNoValidatorFound, "can't load validator for delegation") } bondDenom := keeper.BondDenom(ctx) amount := sdk.NewCoin(bondDenom, val.TokensFromShares(delegation.Shares).TruncateInt()) @@ -513,24 +514,24 @@ func WasmQuerier(k wasmQueryKeeper) func(ctx sdk.Context, request *wasmvmtypes.W case request.Smart != nil: addr, err := sdk.AccAddressFromBech32(request.Smart.ContractAddr) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, request.Smart.ContractAddr) + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, request.Smart.ContractAddr) } msg := types.RawContractMessage(request.Smart.Msg) if err := msg.ValidateBasic(); err != nil { - return nil, sdkerrors.Wrap(err, "json msg") + return nil, errorsmod.Wrap(err, "json msg") } return k.QuerySmart(ctx, addr, msg) case request.Raw != nil: addr, err := sdk.AccAddressFromBech32(request.Raw.ContractAddr) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, request.Raw.ContractAddr) + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, request.Raw.ContractAddr) } return k.QueryRaw(ctx, addr, request.Raw.Key), nil case request.ContractInfo != nil: contractAddr := request.ContractInfo.ContractAddr addr, err := sdk.AccAddressFromBech32(contractAddr) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, contractAddr) + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, contractAddr) } info := k.GetContractInfo(ctx, addr) if info == nil { @@ -590,12 +591,12 @@ func ConvertProtoToJSONMarshal(cdc codec.Codec, protoResponse codec.ProtoMarshal // unmarshal binary into stargate response data structure err := cdc.Unmarshal(bz, protoResponse) if err != nil { - return nil, sdkerrors.Wrap(err, "to proto") + return nil, errorsmod.Wrap(err, "to proto") } bz, err = cdc.MarshalJSON(protoResponse) if err != nil { - return nil, sdkerrors.Wrap(err, "to json") + return nil, errorsmod.Wrap(err, "to json") } protoResponse.Reset() diff --git a/x/wasm/keeper/query_plugins_test.go b/x/wasm/keeper/query_plugins_test.go index af1d966f6..9f82a7f8b 100644 --- a/x/wasm/keeper/query_plugins_test.go +++ b/x/wasm/keeper/query_plugins_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -538,7 +539,7 @@ func TestQueryErrors(t *testing.T) { expErr: wasmvmtypes.NoSuchContract{Addr: "contract-addr"}, }, "no such contract - wrapped": { - src: sdkerrors.Wrap(types.ErrNoSuchContractFn("contract-addr"), "my additional data"), + src: errorsmod.Wrap(types.ErrNoSuchContractFn("contract-addr"), "my additional data"), expErr: wasmvmtypes.NoSuchContract{Addr: "contract-addr"}, }, "no such code": { @@ -546,7 +547,7 @@ func TestQueryErrors(t *testing.T) { expErr: wasmvmtypes.NoSuchCode{CodeID: 123}, }, "no such code - wrapped": { - src: sdkerrors.Wrap(types.ErrNoSuchCodeFn(123), "my additional data"), + src: errorsmod.Wrap(types.ErrNoSuchCodeFn(123), "my additional data"), expErr: wasmvmtypes.NoSuchCode{CodeID: 123}, }, } diff --git a/x/wasm/keeper/reflect_test.go b/x/wasm/keeper/reflect_test.go index 0de20a28c..9f299a446 100644 --- a/x/wasm/keeper/reflect_test.go +++ b/x/wasm/keeper/reflect_test.go @@ -6,6 +6,7 @@ import ( "strings" "testing" + errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -596,7 +597,7 @@ func toReflectRawMsg(cdc codec.Codec, msg sdk.Msg) (wasmvmtypes.CosmosMsg, error } rawBz, err := cdc.MarshalJSON(any) if err != nil { - return wasmvmtypes.CosmosMsg{}, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) + return wasmvmtypes.CosmosMsg{}, errorsmod.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } customMsg, err := json.Marshal(reflectCustomMsg{ Raw: rawBz, @@ -621,12 +622,12 @@ func fromReflectRawMsg(cdc codec.Codec) CustomEncoder { var custom reflectCustomMsg err := json.Unmarshal(msg, &custom) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) + return nil, errorsmod.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } if custom.Raw != nil { var any codectypes.Any if err := cdc.UnmarshalJSON(custom.Raw, &any); err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) + return nil, errorsmod.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } var msg sdk.Msg if err := cdc.UnpackAny(&any, &msg); err != nil { @@ -635,9 +636,9 @@ func fromReflectRawMsg(cdc codec.Codec) CustomEncoder { return []sdk.Msg{msg}, nil } if custom.Debug != "" { - return nil, sdkerrors.Wrapf(types.ErrInvalidMsg, "Custom Debug: %s", custom.Debug) + return nil, errorsmod.Wrapf(types.ErrInvalidMsg, "Custom Debug: %s", custom.Debug) } - return nil, sdkerrors.Wrap(types.ErrInvalidMsg, "Unknown Custom message variant") + return nil, errorsmod.Wrap(types.ErrInvalidMsg, "Unknown Custom message variant") } } @@ -675,7 +676,7 @@ func performCustomQuery(_ sdk.Context, request json.RawMessage) ([]byte, error) var custom reflectCustomQuery err := json.Unmarshal(request, &custom) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) + return nil, errorsmod.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } if custom.Capitalized != nil { msg := strings.ToUpper(custom.Capitalized.Text) @@ -684,5 +685,5 @@ func performCustomQuery(_ sdk.Context, request json.RawMessage) ([]byte, error) if custom.Ping != nil { return json.Marshal(customQueryResponse{Msg: "pong"}) } - return nil, sdkerrors.Wrap(types.ErrInvalidMsg, "Unknown Custom query variant") + return nil, errorsmod.Wrap(types.ErrInvalidMsg, "Unknown Custom query variant") } diff --git a/x/wasm/keeper/relay.go b/x/wasm/keeper/relay.go index 7c3f0b902..1e4e215bd 100644 --- a/x/wasm/keeper/relay.go +++ b/x/wasm/keeper/relay.go @@ -3,10 +3,10 @@ package keeper import ( "time" + errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -36,7 +36,7 @@ func (k Keeper) OnOpenChannel( res, gasUsed, execErr := k.wasmVM.IBCChannelOpen(codeInfo.CodeHash, env, msg, prefixStore, cosmwasmAPI, querier, ctx.GasMeter(), gas, costJSONDeserialization) k.consumeRuntimeGas(ctx, gasUsed) if execErr != nil { - return "", sdkerrors.Wrap(types.ErrExecuteFailed, execErr.Error()) + return "", errorsmod.Wrap(types.ErrExecuteFailed, execErr.Error()) } if res != nil { return res.Version, nil @@ -69,7 +69,7 @@ func (k Keeper) OnConnectChannel( res, gasUsed, execErr := k.wasmVM.IBCChannelConnect(codeInfo.CodeHash, env, msg, prefixStore, cosmwasmAPI, querier, ctx.GasMeter(), gas, costJSONDeserialization) k.consumeRuntimeGas(ctx, gasUsed) if execErr != nil { - return sdkerrors.Wrap(types.ErrExecuteFailed, execErr.Error()) + return errorsmod.Wrap(types.ErrExecuteFailed, execErr.Error()) } return k.handleIBCBasicContractResponse(ctx, contractAddr, contractInfo.IBCPortID, res) @@ -100,7 +100,7 @@ func (k Keeper) OnCloseChannel( res, gasUsed, execErr := k.wasmVM.IBCChannelClose(codeInfo.CodeHash, params, msg, prefixStore, cosmwasmAPI, querier, ctx.GasMeter(), gas, costJSONDeserialization) k.consumeRuntimeGas(ctx, gasUsed) if execErr != nil { - return sdkerrors.Wrap(types.ErrExecuteFailed, execErr.Error()) + return errorsmod.Wrap(types.ErrExecuteFailed, execErr.Error()) } return k.handleIBCBasicContractResponse(ctx, contractAddr, contractInfo.IBCPortID, res) @@ -130,10 +130,10 @@ func (k Keeper) OnRecvPacket( res, gasUsed, execErr := k.wasmVM.IBCPacketReceive(codeInfo.CodeHash, env, msg, prefixStore, cosmwasmAPI, querier, ctx.GasMeter(), gas, costJSONDeserialization) k.consumeRuntimeGas(ctx, gasUsed) if execErr != nil { - return nil, sdkerrors.Wrap(types.ErrExecuteFailed, execErr.Error()) + return nil, errorsmod.Wrap(types.ErrExecuteFailed, execErr.Error()) } if res.Err != "" { // handle error case as before https://github.com/CosmWasm/wasmvm/commit/c300106fe5c9426a495f8e10821e00a9330c56c6 - return nil, sdkerrors.Wrap(types.ErrExecuteFailed, res.Err) + return nil, errorsmod.Wrap(types.ErrExecuteFailed, res.Err) } // note submessage reply results can overwrite the `Acknowledgement` data return k.handleContractResponse(ctx, contractAddr, contractInfo.IBCPortID, res.Ok.Messages, res.Ok.Attributes, res.Ok.Acknowledgement, res.Ok.Events) @@ -164,7 +164,7 @@ func (k Keeper) OnAckPacket( res, gasUsed, execErr := k.wasmVM.IBCPacketAck(codeInfo.CodeHash, env, msg, prefixStore, cosmwasmAPI, querier, ctx.GasMeter(), gas, costJSONDeserialization) k.consumeRuntimeGas(ctx, gasUsed) if execErr != nil { - return sdkerrors.Wrap(types.ErrExecuteFailed, execErr.Error()) + return errorsmod.Wrap(types.ErrExecuteFailed, execErr.Error()) } return k.handleIBCBasicContractResponse(ctx, contractAddr, contractInfo.IBCPortID, res) } @@ -191,7 +191,7 @@ func (k Keeper) OnTimeoutPacket( res, gasUsed, execErr := k.wasmVM.IBCPacketTimeout(codeInfo.CodeHash, env, msg, prefixStore, cosmwasmAPI, querier, ctx.GasMeter(), gas, costJSONDeserialization) k.consumeRuntimeGas(ctx, gasUsed) if execErr != nil { - return sdkerrors.Wrap(types.ErrExecuteFailed, execErr.Error()) + return errorsmod.Wrap(types.ErrExecuteFailed, execErr.Error()) } return k.handleIBCBasicContractResponse(ctx, contractAddr, contractInfo.IBCPortID, res) diff --git a/x/wasm/keeper/snapshotter.go b/x/wasm/keeper/snapshotter.go index 882022ec4..d5217f51d 100644 --- a/x/wasm/keeper/snapshotter.go +++ b/x/wasm/keeper/snapshotter.go @@ -4,9 +4,9 @@ import ( "encoding/hex" "io" + errorsmod "cosmossdk.io/errors" snapshot "github.com/cosmos/cosmos-sdk/snapshots/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -101,13 +101,13 @@ func restoreV1(ctx sdk.Context, k *Keeper, compressedCode []byte) error { } wasmCode, err := ioutils.Uncompress(compressedCode, uint64(types.MaxWasmSize)) if err != nil { - return sdkerrors.Wrap(types.ErrCreateFailed, err.Error()) + return errorsmod.Wrap(types.ErrCreateFailed, err.Error()) } // FIXME: check which codeIDs the checksum matches?? _, err = k.wasmVM.Create(wasmCode) if err != nil { - return sdkerrors.Wrap(types.ErrCreateFailed, err.Error()) + return errorsmod.Wrap(types.ErrCreateFailed, err.Error()) } return nil } @@ -133,7 +133,7 @@ func (ws *WasmSnapshotter) processAllItems( } if err := cb(ctx, ws.wasm, payload); err != nil { - return sdkerrors.Wrap(err, "processing snapshot item") + return errorsmod.Wrap(err, "processing snapshot item") } } diff --git a/x/wasm/keeper/test_common.go b/x/wasm/keeper/test_common.go index d21d3fe76..c86befb2f 100644 --- a/x/wasm/keeper/test_common.go +++ b/x/wasm/keeper/test_common.go @@ -9,6 +9,8 @@ import ( "testing" "time" + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/std" @@ -457,7 +459,7 @@ func TestHandler(k types.ContractOpsKeeper) MessageRouter { return handleExecute(ctx, k, msg) default: errMsg := fmt.Sprintf("unrecognized wasm message type: %T", msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg) } }) } @@ -473,7 +475,7 @@ func (m MessageRouterFunc) Handler(msg sdk.Msg) baseapp.MsgServiceHandler { func handleStoreCode(ctx sdk.Context, k types.ContractOpsKeeper, msg *types.MsgStoreCode) (*sdk.Result, error) { senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) if err != nil { - return nil, sdkerrors.Wrap(err, "sender") + return nil, errorsmod.Wrap(err, "sender") } codeID, _, err := k.Create(ctx, senderAddr, msg.WASMByteCode, msg.InstantiatePermission) if err != nil { @@ -489,12 +491,12 @@ func handleStoreCode(ctx sdk.Context, k types.ContractOpsKeeper, msg *types.MsgS func handleInstantiate(ctx sdk.Context, k types.ContractOpsKeeper, msg *types.MsgInstantiateContract) (*sdk.Result, error) { senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) if err != nil { - return nil, sdkerrors.Wrap(err, "sender") + return nil, errorsmod.Wrap(err, "sender") } var adminAddr sdk.AccAddress if msg.Admin != "" { if adminAddr, err = sdk.AccAddressFromBech32(msg.Admin); err != nil { - return nil, sdkerrors.Wrap(err, "admin") + return nil, errorsmod.Wrap(err, "admin") } } @@ -512,11 +514,11 @@ func handleInstantiate(ctx sdk.Context, k types.ContractOpsKeeper, msg *types.Ms func handleExecute(ctx sdk.Context, k types.ContractOpsKeeper, msg *types.MsgExecuteContract) (*sdk.Result, error) { senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) if err != nil { - return nil, sdkerrors.Wrap(err, "sender") + return nil, errorsmod.Wrap(err, "sender") } contractAddr, err := sdk.AccAddressFromBech32(msg.Contract) if err != nil { - return nil, sdkerrors.Wrap(err, "admin") + return nil, errorsmod.Wrap(err, "admin") } data, err := k.Execute(ctx, contractAddr, senderAddr, msg.Msg, msg.Funds) if err != nil { diff --git a/x/wasm/keeper/wasmtesting/mock_engine.go b/x/wasm/keeper/wasmtesting/mock_engine.go index 10c7fdfed..ca54dc992 100644 --- a/x/wasm/keeper/wasmtesting/mock_engine.go +++ b/x/wasm/keeper/wasmtesting/mock_engine.go @@ -4,9 +4,10 @@ import ( "bytes" "crypto/sha256" + errorsmod "cosmossdk.io/errors" + wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/tendermint/tendermint/libs/rand" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -323,7 +324,7 @@ func NewIBCContractMockWasmer(c IBCContractCallbacks) *MockWasmer { func HashOnlyCreateFn(code wasmvm.WasmCode) (wasmvm.Checksum, error) { if code == nil { - return nil, sdkerrors.Wrap(types.ErrInvalid, "wasm code must not be nil") + return nil, errorsmod.Wrap(types.ErrInvalid, "wasm code must not be nil") } hash := sha256.Sum256(code) return hash[:], nil diff --git a/x/wasm/relay_test.go b/x/wasm/relay_test.go index ec2832772..4a25d0b89 100644 --- a/x/wasm/relay_test.go +++ b/x/wasm/relay_test.go @@ -6,10 +6,10 @@ import ( "testing" "time" + errorsmod "cosmossdk.io/errors" wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -699,7 +699,7 @@ func (c *ackReceiverContract) IBCPacketReceive(codeID wasmvm.Checksum, env wasmv ctx := c.chain.GetContext() // HACK: please note that this is not reverted after checkTX err := c.chain.App.TransferKeeper.OnRecvPacket(ctx, ibcPacket, src) if err != nil { - return nil, 0, sdkerrors.Wrap(err, "within our smart contract") + return nil, 0, errorsmod.Wrap(err, "within our smart contract") } var log []wasmvmtypes.EventAttribute // note: all events are under `wasm` event type @@ -724,7 +724,7 @@ func (c *ackReceiverContract) IBCPacketAck(codeID wasmvm.Checksum, env wasmvmtyp ibcPacket := toIBCPacket(msg.OriginalPacket) err := c.chain.App.TransferKeeper.OnAcknowledgementPacket(ctx, ibcPacket, data, ack) if err != nil { - return nil, 0, sdkerrors.Wrap(err, "within our smart contract") + return nil, 0, errorsmod.Wrap(err, "within our smart contract") } return &wasmvmtypes.IBCBasicResponse{}, 0, nil diff --git a/x/wasm/simulation/operations.go b/x/wasm/simulation/operations.go index 4e402290c..06c430eab 100644 --- a/x/wasm/simulation/operations.go +++ b/x/wasm/simulation/operations.go @@ -5,12 +5,13 @@ import ( "math/rand" "os" + errorsmod "cosmossdk.io/errors" + wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/auth/tx" @@ -519,23 +520,23 @@ func DefaultSimulationExecuteSenderSelector(wasmKeeper WasmKeeper, ctx sdk.Conte var none simtypes.Account bz, err := json.Marshal(testdata.ReflectQueryMsg{Owner: &struct{}{}}) if err != nil { - return none, sdkerrors.Wrap(err, "build smart query") + return none, errorsmod.Wrap(err, "build smart query") } got, err := wasmKeeper.QuerySmart(ctx, contractAddr, bz) if err != nil { - return none, sdkerrors.Wrap(err, "exec smart query") + return none, errorsmod.Wrap(err, "exec smart query") } var ownerRes testdata.OwnerResponse if err := json.Unmarshal(got, &ownerRes); err != nil || ownerRes.Owner == "" { - return none, sdkerrors.Wrap(err, "parse smart query response") + return none, errorsmod.Wrap(err, "parse smart query response") } ownerAddr, err := sdk.AccAddressFromBech32(ownerRes.Owner) if err != nil { - return none, sdkerrors.Wrap(err, "parse contract owner address") + return none, errorsmod.Wrap(err, "parse contract owner address") } simAccount, ok := simtypes.FindAccount(accs, ownerAddr) if !ok { - return none, sdkerrors.Wrap(err, "unknown contract owner address") + return none, errorsmod.Wrap(err, "unknown contract owner address") } return simAccount, nil } diff --git a/x/wasm/types/authz.go b/x/wasm/types/authz.go index 1bc0fb8dd..6cce369ba 100644 --- a/x/wasm/types/authz.go +++ b/x/wasm/types/authz.go @@ -3,13 +3,12 @@ package types import ( "strings" - "github.com/cosmos/gogoproto/proto" - + errorsmod "cosmossdk.io/errors" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authztypes "github.com/cosmos/cosmos-sdk/x/authz" + "github.com/cosmos/gogoproto/proto" ) const gasDeserializationCostPerByte = uint64(1) @@ -109,7 +108,7 @@ func validateGrants(g []ContractGrant) error { } for i, v := range g { if err := v.ValidateBasic(); err != nil { - return sdkerrors.Wrapf(err, "position %d", i) + return errorsmod.Wrapf(err, "position %d", i) } } // allow multiple grants for a contract: @@ -146,7 +145,7 @@ func AcceptGrantedMessage[T AuthzableWasmMsg](ctx sdk.Context, grants []Contract result, err := g.GetLimit().Accept(ctx, exec) switch { case err != nil: - return authztypes.AcceptResponse{}, sdkerrors.Wrap(err, "limit") + return authztypes.AcceptResponse{}, errorsmod.Wrap(err, "limit") case result == nil: // sanity check return authztypes.AcceptResponse{}, sdkerrors.ErrInvalidType.Wrap("limit result must not be nil") case !result.Accepted: @@ -158,7 +157,7 @@ func AcceptGrantedMessage[T AuthzableWasmMsg](ctx sdk.Context, grants []Contract ok, err := g.GetFilter().Accept(ctx, exec.GetMsg()) switch { case err != nil: - return authztypes.AcceptResponse{}, sdkerrors.Wrap(err, "filter") + return authztypes.AcceptResponse{}, errorsmod.Wrap(err, "filter") case !ok: // no limit update and continue with next grant continue @@ -229,7 +228,7 @@ func NewContractGrant(contract sdk.AccAddress, limit ContractAuthzLimitX, filter } anyFilter, err := cdctypes.NewAnyWithValue(pFilter) if err != nil { - return nil, sdkerrors.Wrap(err, "filter") + return nil, errorsmod.Wrap(err, "filter") } return ContractGrant{ Contract: contract.String(), @@ -245,7 +244,7 @@ func (g ContractGrant) WithNewLimits(limit ContractAuthzLimitX) (*ContractGrant, } anyLimit, err := cdctypes.NewAnyWithValue(pLimit) if err != nil { - return nil, sdkerrors.Wrap(err, "limit") + return nil, errorsmod.Wrap(err, "limit") } return &ContractGrant{ @@ -259,11 +258,11 @@ func (g ContractGrant) WithNewLimits(limit ContractAuthzLimitX) (*ContractGrant, func (g ContractGrant) UnpackInterfaces(unpacker cdctypes.AnyUnpacker) error { var f ContractAuthzFilterX if err := unpacker.UnpackAny(g.Filter, &f); err != nil { - return sdkerrors.Wrap(err, "filter") + return errorsmod.Wrap(err, "filter") } var l ContractAuthzLimitX if err := unpacker.UnpackAny(g.Limit, &l); err != nil { - return sdkerrors.Wrap(err, "limit") + return errorsmod.Wrap(err, "limit") } return nil } @@ -295,15 +294,15 @@ func (g ContractGrant) GetFilter() ContractAuthzFilterX { // ValidateBasic validates the grant func (g ContractGrant) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(g.Contract); err != nil { - return sdkerrors.Wrap(err, "contract") + return errorsmod.Wrap(err, "contract") } // execution limits if err := g.GetLimit().ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "limit") + return errorsmod.Wrap(err, "limit") } // filter if err := g.GetFilter().ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "filter") + return errorsmod.Wrap(err, "filter") } return nil } @@ -528,7 +527,7 @@ func (l CombinedLimit) ValidateBasic() error { return ErrEmpty.Wrap("amounts") } if err := l.Amounts.Validate(); err != nil { - return sdkerrors.Wrap(err, "amounts") + return errorsmod.Wrap(err, "amounts") } return nil } diff --git a/x/wasm/types/errors.go b/x/wasm/types/errors.go index 70b854cf9..378c25d67 100644 --- a/x/wasm/types/errors.go +++ b/x/wasm/types/errors.go @@ -1,7 +1,7 @@ package types import ( - sdkErrors "cosmossdk.io/errors" + errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" ) @@ -12,77 +12,77 @@ var ( // Note: never use code 1 for any errors - that is reserved for ErrInternal in the core cosmos sdk // ErrCreateFailed error for wasm code that has already been uploaded or failed - ErrCreateFailed = sdkErrors.Register(DefaultCodespace, 2, "create wasm contract failed") + ErrCreateFailed = errorsmod.Register(DefaultCodespace, 2, "create wasm contract failed") // ErrAccountExists error for a contract account that already exists - ErrAccountExists = sdkErrors.Register(DefaultCodespace, 3, "contract account already exists") + ErrAccountExists = errorsmod.Register(DefaultCodespace, 3, "contract account already exists") // ErrInstantiateFailed error for rust instantiate contract failure - ErrInstantiateFailed = sdkErrors.Register(DefaultCodespace, 4, "instantiate wasm contract failed") + ErrInstantiateFailed = errorsmod.Register(DefaultCodespace, 4, "instantiate wasm contract failed") // ErrExecuteFailed error for rust execution contract failure - ErrExecuteFailed = sdkErrors.Register(DefaultCodespace, 5, "execute wasm contract failed") + ErrExecuteFailed = errorsmod.Register(DefaultCodespace, 5, "execute wasm contract failed") // ErrGasLimit error for out of gas - ErrGasLimit = sdkErrors.Register(DefaultCodespace, 6, "insufficient gas") + ErrGasLimit = errorsmod.Register(DefaultCodespace, 6, "insufficient gas") // ErrInvalidGenesis error for invalid genesis file syntax - ErrInvalidGenesis = sdkErrors.Register(DefaultCodespace, 7, "invalid genesis") + ErrInvalidGenesis = errorsmod.Register(DefaultCodespace, 7, "invalid genesis") // ErrNotFound error for an entry not found in the store - ErrNotFound = sdkErrors.Register(DefaultCodespace, 8, "not found") + ErrNotFound = errorsmod.Register(DefaultCodespace, 8, "not found") // ErrQueryFailed error for rust smart query contract failure - ErrQueryFailed = sdkErrors.Register(DefaultCodespace, 9, "query wasm contract failed") + ErrQueryFailed = errorsmod.Register(DefaultCodespace, 9, "query wasm contract failed") // ErrInvalidMsg error when we cannot process the error returned from the contract - ErrInvalidMsg = sdkErrors.Register(DefaultCodespace, 10, "invalid CosmosMsg from the contract") + ErrInvalidMsg = errorsmod.Register(DefaultCodespace, 10, "invalid CosmosMsg from the contract") // ErrMigrationFailed error for rust execution contract failure - ErrMigrationFailed = sdkErrors.Register(DefaultCodespace, 11, "migrate wasm contract failed") + ErrMigrationFailed = errorsmod.Register(DefaultCodespace, 11, "migrate wasm contract failed") // ErrEmpty error for empty content - ErrEmpty = sdkErrors.Register(DefaultCodespace, 12, "empty") + ErrEmpty = errorsmod.Register(DefaultCodespace, 12, "empty") // ErrLimit error for content that exceeds a limit - ErrLimit = sdkErrors.Register(DefaultCodespace, 13, "exceeds limit") + ErrLimit = errorsmod.Register(DefaultCodespace, 13, "exceeds limit") // ErrInvalid error for content that is invalid in this context - ErrInvalid = sdkErrors.Register(DefaultCodespace, 14, "invalid") + ErrInvalid = errorsmod.Register(DefaultCodespace, 14, "invalid") // ErrDuplicate error for content that exists - ErrDuplicate = sdkErrors.Register(DefaultCodespace, 15, "duplicate") + ErrDuplicate = errorsmod.Register(DefaultCodespace, 15, "duplicate") // ErrMaxIBCChannels error for maximum number of ibc channels reached - ErrMaxIBCChannels = sdkErrors.Register(DefaultCodespace, 16, "max transfer channels") + ErrMaxIBCChannels = errorsmod.Register(DefaultCodespace, 16, "max transfer channels") // ErrUnsupportedForContract error when a capability is used that is not supported for/ by this contract - ErrUnsupportedForContract = sdkErrors.Register(DefaultCodespace, 17, "unsupported for this contract") + ErrUnsupportedForContract = errorsmod.Register(DefaultCodespace, 17, "unsupported for this contract") // ErrPinContractFailed error for pinning contract failures - ErrPinContractFailed = sdkErrors.Register(DefaultCodespace, 18, "pinning contract failed") + ErrPinContractFailed = errorsmod.Register(DefaultCodespace, 18, "pinning contract failed") // ErrUnpinContractFailed error for unpinning contract failures - ErrUnpinContractFailed = sdkErrors.Register(DefaultCodespace, 19, "unpinning contract failed") + ErrUnpinContractFailed = errorsmod.Register(DefaultCodespace, 19, "unpinning contract failed") // ErrUnknownMsg error by a message handler to show that it is not responsible for this message type - ErrUnknownMsg = sdkErrors.Register(DefaultCodespace, 20, "unknown message from the contract") + ErrUnknownMsg = errorsmod.Register(DefaultCodespace, 20, "unknown message from the contract") // ErrInvalidEvent error if an attribute/event from the contract is invalid - ErrInvalidEvent = sdkErrors.Register(DefaultCodespace, 21, "invalid event") + ErrInvalidEvent = errorsmod.Register(DefaultCodespace, 21, "invalid event") // ErrNoSuchContractFn error factory for an error when an address does not belong to a contract - ErrNoSuchContractFn = WasmVMFlavouredErrorFactory(sdkErrors.Register(DefaultCodespace, 22, "no such contract"), + ErrNoSuchContractFn = WasmVMFlavouredErrorFactory(errorsmod.Register(DefaultCodespace, 22, "no such contract"), func(addr string) error { return wasmvmtypes.NoSuchContract{Addr: addr} }, ) // code 23 -26 were used for json parser // ErrExceedMaxQueryStackSize error if max query stack size is exceeded - ErrExceedMaxQueryStackSize = sdkErrors.Register(DefaultCodespace, 27, "max query stack size exceeded") + ErrExceedMaxQueryStackSize = errorsmod.Register(DefaultCodespace, 27, "max query stack size exceeded") // ErrNoSuchCodeFn factory for an error when a code id does not belong to a code info - ErrNoSuchCodeFn = WasmVMFlavouredErrorFactory(sdkErrors.Register(DefaultCodespace, 28, "no such code"), + ErrNoSuchCodeFn = WasmVMFlavouredErrorFactory(errorsmod.Register(DefaultCodespace, 28, "no such code"), func(id uint64) error { return wasmvmtypes.NoSuchCode{CodeID: id} }, ) ) @@ -97,17 +97,17 @@ var _ WasmVMErrorable = WasmVMFlavouredError{} // WasmVMFlavouredError wrapper for sdk error that supports wasmvm error types type WasmVMFlavouredError struct { - sdkErr *sdkErrors.Error + sdkErr *errorsmod.Error wasmVMErr error } // NewWasmVMFlavouredError constructor -func NewWasmVMFlavouredError(sdkErr *sdkErrors.Error, wasmVMErr error) WasmVMFlavouredError { +func NewWasmVMFlavouredError(sdkErr *errorsmod.Error, wasmVMErr error) WasmVMFlavouredError { return WasmVMFlavouredError{sdkErr: sdkErr, wasmVMErr: wasmVMErr} } // WasmVMFlavouredErrorFactory is a factory method to build a WasmVMFlavouredError type -func WasmVMFlavouredErrorFactory[T any](sdkErr *sdkErrors.Error, wasmVMErrBuilder func(T) error) func(T) WasmVMFlavouredError { +func WasmVMFlavouredErrorFactory[T any](sdkErr *errorsmod.Error, wasmVMErrBuilder func(T) error) func(T) WasmVMFlavouredError { if wasmVMErrBuilder == nil { panic("builder function required") } @@ -141,10 +141,10 @@ func (e WasmVMFlavouredError) Cause() error { // Wrap extends this error with additional information. // It's a handy function to call Wrap with sdk errors. -func (e WasmVMFlavouredError) Wrap(desc string) error { return sdkErrors.Wrap(e, desc) } +func (e WasmVMFlavouredError) Wrap(desc string) error { return errorsmod.Wrap(e, desc) } // Wrapf extends this error with additional information. // It's a handy function to call Wrapf with sdk errors. func (e WasmVMFlavouredError) Wrapf(desc string, args ...interface{}) error { - return sdkErrors.Wrapf(e, desc, args...) + return errorsmod.Wrapf(e, desc, args...) } diff --git a/x/wasm/types/genesis.go b/x/wasm/types/genesis.go index f14dbc3d7..8a5a15696 100644 --- a/x/wasm/types/genesis.go +++ b/x/wasm/types/genesis.go @@ -1,35 +1,35 @@ package types import ( + errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) func (s Sequence) ValidateBasic() error { if len(s.IDKey) == 0 { - return sdkerrors.Wrap(ErrEmpty, "id key") + return errorsmod.Wrap(ErrEmpty, "id key") } return nil } func (s GenesisState) ValidateBasic() error { if err := s.Params.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "params") + return errorsmod.Wrap(err, "params") } for i := range s.Codes { if err := s.Codes[i].ValidateBasic(); err != nil { - return sdkerrors.Wrapf(err, "code: %d", i) + return errorsmod.Wrapf(err, "code: %d", i) } } for i := range s.Contracts { if err := s.Contracts[i].ValidateBasic(); err != nil { - return sdkerrors.Wrapf(err, "contract: %d", i) + return errorsmod.Wrapf(err, "contract: %d", i) } } for i := range s.Sequences { if err := s.Sequences[i].ValidateBasic(); err != nil { - return sdkerrors.Wrapf(err, "sequence: %d", i) + return errorsmod.Wrapf(err, "sequence: %d", i) } } @@ -38,31 +38,31 @@ func (s GenesisState) ValidateBasic() error { func (c Code) ValidateBasic() error { if c.CodeID == 0 { - return sdkerrors.Wrap(ErrEmpty, "code id") + return errorsmod.Wrap(ErrEmpty, "code id") } if err := c.CodeInfo.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "code info") + return errorsmod.Wrap(err, "code info") } if err := validateWasmCode(c.CodeBytes, MaxProposalWasmSize); err != nil { - return sdkerrors.Wrap(err, "code bytes") + return errorsmod.Wrap(err, "code bytes") } return nil } func (c Contract) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(c.ContractAddress); err != nil { - return sdkerrors.Wrap(err, "contract address") + return errorsmod.Wrap(err, "contract address") } if err := c.ContractInfo.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "contract info") + return errorsmod.Wrap(err, "contract info") } if c.ContractInfo.Created == nil { - return sdkerrors.Wrap(ErrInvalid, "created must not be empty") + return errorsmod.Wrap(ErrInvalid, "created must not be empty") } for i := range c.ContractState { if err := c.ContractState[i].ValidateBasic(); err != nil { - return sdkerrors.Wrapf(err, "contract state %d", i) + return errorsmod.Wrapf(err, "contract state %d", i) } } if len(c.ContractCodeHistory) == 0 { @@ -70,7 +70,7 @@ func (c Contract) ValidateBasic() error { } for i, v := range c.ContractCodeHistory { if err := v.ValidateBasic(); err != nil { - return sdkerrors.Wrapf(err, "code history element %d", i) + return errorsmod.Wrapf(err, "code history element %d", i) } } return nil diff --git a/x/wasm/types/params.go b/x/wasm/types/params.go index c5be18826..b645f4fdc 100644 --- a/x/wasm/types/params.go +++ b/x/wasm/types/params.go @@ -4,8 +4,8 @@ import ( "encoding/json" "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/gogoproto/jsonpb" "github.com/pkg/errors" @@ -44,7 +44,7 @@ func (a AccessType) With(addrs ...sdk.AccAddress) AccessConfig { bech32Addrs[i] = v.String() } if err := assertValidAddresses(bech32Addrs); err != nil { - panic(sdkerrors.Wrap(err, "addresses")) + panic(errorsmod.Wrap(err, "addresses")) } return AccessConfig{Permission: AccessTypeAnyOfAddresses, Addresses: bech32Addrs} } @@ -152,24 +152,24 @@ func validateAccessType(i interface{}) error { return fmt.Errorf("invalid parameter type: %T", i) } if a == AccessTypeUnspecified { - return sdkerrors.Wrap(ErrEmpty, "type") + return errorsmod.Wrap(ErrEmpty, "type") } for _, v := range AllAccessTypes { if v == a { return nil } } - return sdkerrors.Wrapf(ErrInvalid, "unknown type: %q", a) + return errorsmod.Wrapf(ErrInvalid, "unknown type: %q", a) } // ValidateBasic performs basic validation func (a AccessConfig) ValidateBasic() error { switch a.Permission { case AccessTypeUnspecified: - return sdkerrors.Wrap(ErrEmpty, "type") + return errorsmod.Wrap(ErrEmpty, "type") case AccessTypeNobody, AccessTypeEverybody: if len(a.Address) != 0 { - return sdkerrors.Wrap(ErrInvalid, "address not allowed for this type") + return errorsmod.Wrap(ErrInvalid, "address not allowed for this type") } return nil case AccessTypeOnlyAddress: @@ -182,9 +182,9 @@ func (a AccessConfig) ValidateBasic() error { if a.Address != "" { return ErrInvalid.Wrap("address field set") } - return sdkerrors.Wrap(assertValidAddresses(a.Addresses), "addresses") + return errorsmod.Wrap(assertValidAddresses(a.Addresses), "addresses") } - return sdkerrors.Wrapf(ErrInvalid, "unknown type: %q", a.Permission) + return errorsmod.Wrapf(ErrInvalid, "unknown type: %q", a.Permission) } func assertValidAddresses(addrs []string) error { @@ -194,7 +194,7 @@ func assertValidAddresses(addrs []string) error { idx := make(map[string]struct{}, len(addrs)) for _, a := range addrs { if _, err := sdk.AccAddressFromBech32(a); err != nil { - return sdkerrors.Wrapf(err, "address: %s", a) + return errorsmod.Wrapf(err, "address: %s", a) } if _, exists := idx[a]; exists { return ErrDuplicate.Wrapf("address: %s", a) diff --git a/x/wasm/types/proposal.go b/x/wasm/types/proposal.go index 2556c588f..468f45b17 100644 --- a/x/wasm/types/proposal.go +++ b/x/wasm/types/proposal.go @@ -6,6 +6,7 @@ import ( "fmt" "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -59,7 +60,7 @@ func ConvertToProposals(keys []string) ([]ProposalType, error) { proposals := make([]ProposalType, len(keys)) for i, key := range keys { if _, ok := valid[key]; !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "'%s' is not a valid ProposalType", key) + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "'%s' is not a valid ProposalType", key) } proposals[i] = ProposalType(key) } @@ -113,21 +114,21 @@ func (p StoreCodeProposal) ValidateBasic() error { return err } if _, err := sdk.AccAddressFromBech32(p.RunAs); err != nil { - return sdkerrors.Wrap(err, "run as") + return errorsmod.Wrap(err, "run as") } if err := validateWasmCode(p.WASMByteCode, MaxProposalWasmSize); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "code bytes %s", err.Error()) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "code bytes %s", err.Error()) } if p.InstantiatePermission != nil { if err := p.InstantiatePermission.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "instantiate permission") + return errorsmod.Wrap(err, "instantiate permission") } } if err := ValidateVerificationInfo(p.Source, p.Builder, p.CodeHash); err != nil { - return sdkerrors.Wrapf(err, "code verification info") + return errorsmod.Wrapf(err, "code verification info") } return nil } @@ -201,11 +202,11 @@ func (p InstantiateContractProposal) ValidateBasic() error { return err } if _, err := sdk.AccAddressFromBech32(p.RunAs); err != nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "run as") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "run as") } if p.CodeID == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "code id is required") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "code id is required") } if err := ValidateLabel(p.Label); err != nil { @@ -222,7 +223,7 @@ func (p InstantiateContractProposal) ValidateBasic() error { } } if err := p.Msg.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "payload msg") + return errorsmod.Wrap(err, "payload msg") } return nil } @@ -301,7 +302,7 @@ func (p InstantiateContract2Proposal) ValidateBasic() error { } // Validate run as if _, err := sdk.AccAddressFromBech32(p.RunAs); err != nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "run as") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "run as") } // Validate admin if len(p.Admin) != 0 { @@ -311,7 +312,7 @@ func (p InstantiateContract2Proposal) ValidateBasic() error { } // Validate codeid if p.CodeID == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "code id is required") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "code id is required") } // Validate label if err := ValidateLabel(p.Label); err != nil { @@ -319,7 +320,7 @@ func (p InstantiateContract2Proposal) ValidateBasic() error { } // Validate msg if err := p.Msg.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "payload msg") + return errorsmod.Wrap(err, "payload msg") } // Validate funds if !p.Funds.IsValid() { @@ -327,7 +328,7 @@ func (p InstantiateContract2Proposal) ValidateBasic() error { } // Validate salt if len(p.Salt) == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "salt is required") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "salt is required") } return nil } @@ -424,20 +425,20 @@ func (p StoreAndInstantiateContractProposal) ValidateBasic() error { return err } if _, err := sdk.AccAddressFromBech32(p.RunAs); err != nil { - return sdkerrors.Wrap(err, "run as") + return errorsmod.Wrap(err, "run as") } if err := validateWasmCode(p.WASMByteCode, MaxProposalWasmSize); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "code bytes %s", err.Error()) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "code bytes %s", err.Error()) } if err := ValidateVerificationInfo(p.Source, p.Builder, p.CodeHash); err != nil { - return sdkerrors.Wrap(err, "code info") + return errorsmod.Wrap(err, "code info") } if p.InstantiatePermission != nil { if err := p.InstantiatePermission.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "instantiate permission") + return errorsmod.Wrap(err, "instantiate permission") } } @@ -455,7 +456,7 @@ func (p StoreAndInstantiateContractProposal) ValidateBasic() error { } } if err := p.Msg.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "payload msg") + return errorsmod.Wrap(err, "payload msg") } return nil } @@ -546,13 +547,13 @@ func (p MigrateContractProposal) ValidateBasic() error { return err } if p.CodeID == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "code_id is required") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "code_id is required") } if _, err := sdk.AccAddressFromBech32(p.Contract); err != nil { - return sdkerrors.Wrap(err, "contract") + return errorsmod.Wrap(err, "contract") } if err := p.Msg.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "payload msg") + return errorsmod.Wrap(err, "payload msg") } return nil } @@ -617,10 +618,10 @@ func (p SudoContractProposal) ValidateBasic() error { return err } if _, err := sdk.AccAddressFromBech32(p.Contract); err != nil { - return sdkerrors.Wrap(err, "contract") + return errorsmod.Wrap(err, "contract") } if err := p.Msg.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "payload msg") + return errorsmod.Wrap(err, "payload msg") } return nil } @@ -679,16 +680,16 @@ func (p ExecuteContractProposal) ValidateBasic() error { return err } if _, err := sdk.AccAddressFromBech32(p.Contract); err != nil { - return sdkerrors.Wrap(err, "contract") + return errorsmod.Wrap(err, "contract") } if _, err := sdk.AccAddressFromBech32(p.RunAs); err != nil { - return sdkerrors.Wrap(err, "run as") + return errorsmod.Wrap(err, "run as") } if !p.Funds.IsValid() { return sdkerrors.ErrInvalidCoins } if err := p.Msg.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "payload msg") + return errorsmod.Wrap(err, "payload msg") } return nil } @@ -751,10 +752,10 @@ func (p UpdateAdminProposal) ValidateBasic() error { return err } if _, err := sdk.AccAddressFromBech32(p.Contract); err != nil { - return sdkerrors.Wrap(err, "contract") + return errorsmod.Wrap(err, "contract") } if _, err := sdk.AccAddressFromBech32(p.NewAdmin); err != nil { - return sdkerrors.Wrap(err, "new admin") + return errorsmod.Wrap(err, "new admin") } return nil } @@ -795,7 +796,7 @@ func (p ClearAdminProposal) ValidateBasic() error { return err } if _, err := sdk.AccAddressFromBech32(p.Contract); err != nil { - return sdkerrors.Wrap(err, "contract") + return errorsmod.Wrap(err, "contract") } return nil } @@ -839,7 +840,7 @@ func (p PinCodesProposal) ValidateBasic() error { return err } if len(p.CodeIDs) == 0 { - return sdkerrors.Wrap(ErrEmpty, "code ids") + return errorsmod.Wrap(ErrEmpty, "code ids") } return nil } @@ -883,7 +884,7 @@ func (p UnpinCodesProposal) ValidateBasic() error { return err } if len(p.CodeIDs) == 0 { - return sdkerrors.Wrap(ErrEmpty, "code ids") + return errorsmod.Wrap(ErrEmpty, "code ids") } return nil } @@ -899,22 +900,22 @@ func (p UnpinCodesProposal) String() string { func validateProposalCommons(title, description string) error { if strings.TrimSpace(title) != title { - return sdkerrors.Wrap(govtypes.ErrInvalidProposalContent, "proposal title must not start/end with white spaces") + return errorsmod.Wrap(govtypes.ErrInvalidProposalContent, "proposal title must not start/end with white spaces") } if len(title) == 0 { - return sdkerrors.Wrap(govtypes.ErrInvalidProposalContent, "proposal title cannot be blank") + return errorsmod.Wrap(govtypes.ErrInvalidProposalContent, "proposal title cannot be blank") } if len(title) > v1beta1.MaxTitleLength { - return sdkerrors.Wrapf(govtypes.ErrInvalidProposalContent, "proposal title is longer than max length of %d", v1beta1.MaxTitleLength) + return errorsmod.Wrapf(govtypes.ErrInvalidProposalContent, "proposal title is longer than max length of %d", v1beta1.MaxTitleLength) } if strings.TrimSpace(description) != description { - return sdkerrors.Wrap(govtypes.ErrInvalidProposalContent, "proposal description must not start/end with white spaces") + return errorsmod.Wrap(govtypes.ErrInvalidProposalContent, "proposal description must not start/end with white spaces") } if len(description) == 0 { - return sdkerrors.Wrap(govtypes.ErrInvalidProposalContent, "proposal description cannot be blank") + return errorsmod.Wrap(govtypes.ErrInvalidProposalContent, "proposal description cannot be blank") } if len(description) > v1beta1.MaxDescriptionLength { - return sdkerrors.Wrapf(govtypes.ErrInvalidProposalContent, "proposal description is longer than max length of %d", v1beta1.MaxDescriptionLength) + return errorsmod.Wrapf(govtypes.ErrInvalidProposalContent, "proposal description is longer than max length of %d", v1beta1.MaxDescriptionLength) } return nil } @@ -951,16 +952,16 @@ func (p UpdateInstantiateConfigProposal) ValidateBasic() error { return err } if len(p.AccessConfigUpdates) == 0 { - return sdkerrors.Wrap(ErrEmpty, "code updates") + return errorsmod.Wrap(ErrEmpty, "code updates") } dedup := make(map[uint64]bool) for _, codeUpdate := range p.AccessConfigUpdates { _, found := dedup[codeUpdate.CodeID] if found { - return sdkerrors.Wrapf(ErrDuplicate, "duplicate code: %d", codeUpdate.CodeID) + return errorsmod.Wrapf(ErrDuplicate, "duplicate code: %d", codeUpdate.CodeID) } if err := codeUpdate.InstantiatePermission.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "instantiate permission") + return errorsmod.Wrap(err, "instantiate permission") } dedup[codeUpdate.CodeID] = true } diff --git a/x/wasm/types/tx.go b/x/wasm/types/tx.go index 045f5341e..69f9a2f79 100644 --- a/x/wasm/types/tx.go +++ b/x/wasm/types/tx.go @@ -6,6 +6,7 @@ import ( "errors" "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -61,12 +62,12 @@ func (msg MsgStoreCode) ValidateBasic() error { } if err := validateWasmCode(msg.WASMByteCode, MaxWasmSize); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "code bytes %s", err.Error()) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "code bytes %s", err.Error()) } if msg.InstantiatePermission != nil { if err := msg.InstantiatePermission.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "instantiate permission") + return errorsmod.Wrap(err, "instantiate permission") } // AccessTypeOnlyAddress is still considered valid as legacy instantiation permission // but not for new contracts @@ -99,15 +100,15 @@ func (msg MsgInstantiateContract) Type() string { func (msg MsgInstantiateContract) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { - return sdkerrors.Wrap(err, "sender") + return errorsmod.Wrap(err, "sender") } if msg.CodeID == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "code id is required") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "code id is required") } if err := ValidateLabel(msg.Label); err != nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "label is required") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "label is required") } if !msg.Funds.IsValid() { @@ -116,11 +117,11 @@ func (msg MsgInstantiateContract) ValidateBasic() error { if len(msg.Admin) != 0 { if _, err := sdk.AccAddressFromBech32(msg.Admin); err != nil { - return sdkerrors.Wrap(err, "admin") + return errorsmod.Wrap(err, "admin") } } if err := msg.Msg.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "payload msg") + return errorsmod.Wrap(err, "payload msg") } return nil } @@ -147,17 +148,17 @@ func (msg MsgExecuteContract) Type() string { func (msg MsgExecuteContract) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { - return sdkerrors.Wrap(err, "sender") + return errorsmod.Wrap(err, "sender") } if _, err := sdk.AccAddressFromBech32(msg.Contract); err != nil { - return sdkerrors.Wrap(err, "contract") + return errorsmod.Wrap(err, "contract") } if !msg.Funds.IsValid() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "sentFunds") + return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "sentFunds") } if err := msg.Msg.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "payload msg") + return errorsmod.Wrap(err, "payload msg") } return nil } @@ -199,17 +200,17 @@ func (msg MsgMigrateContract) Type() string { func (msg MsgMigrateContract) ValidateBasic() error { if msg.CodeID == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "code id is required") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "code id is required") } if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { - return sdkerrors.Wrap(err, "sender") + return errorsmod.Wrap(err, "sender") } if _, err := sdk.AccAddressFromBech32(msg.Contract); err != nil { - return sdkerrors.Wrap(err, "contract") + return errorsmod.Wrap(err, "contract") } if err := msg.Msg.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "payload msg") + return errorsmod.Wrap(err, "payload msg") } return nil @@ -252,16 +253,16 @@ func (msg MsgUpdateAdmin) Type() string { func (msg MsgUpdateAdmin) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { - return sdkerrors.Wrap(err, "sender") + return errorsmod.Wrap(err, "sender") } if _, err := sdk.AccAddressFromBech32(msg.Contract); err != nil { - return sdkerrors.Wrap(err, "contract") + return errorsmod.Wrap(err, "contract") } if _, err := sdk.AccAddressFromBech32(msg.NewAdmin); err != nil { - return sdkerrors.Wrap(err, "new admin") + return errorsmod.Wrap(err, "new admin") } if strings.EqualFold(msg.Sender, msg.NewAdmin) { - return sdkerrors.Wrap(ErrInvalidMsg, "new admin is the same as the old") + return errorsmod.Wrap(ErrInvalidMsg, "new admin is the same as the old") } return nil } @@ -288,10 +289,10 @@ func (msg MsgClearAdmin) Type() string { func (msg MsgClearAdmin) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { - return sdkerrors.Wrap(err, "sender") + return errorsmod.Wrap(err, "sender") } if _, err := sdk.AccAddressFromBech32(msg.Contract); err != nil { - return sdkerrors.Wrap(err, "contract") + return errorsmod.Wrap(err, "contract") } return nil } @@ -360,15 +361,15 @@ func (msg MsgInstantiateContract2) Type() string { func (msg MsgInstantiateContract2) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { - return sdkerrors.Wrap(err, "sender") + return errorsmod.Wrap(err, "sender") } if msg.CodeID == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "code id is required") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "code id is required") } if err := ValidateLabel(msg.Label); err != nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "label is required") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "label is required") } if !msg.Funds.IsValid() { @@ -377,14 +378,14 @@ func (msg MsgInstantiateContract2) ValidateBasic() error { if len(msg.Admin) != 0 { if _, err := sdk.AccAddressFromBech32(msg.Admin); err != nil { - return sdkerrors.Wrap(err, "admin") + return errorsmod.Wrap(err, "admin") } } if err := msg.Msg.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "payload msg") + return errorsmod.Wrap(err, "payload msg") } if err := ValidateSalt(msg.Salt); err != nil { - return sdkerrors.Wrap(err, "salt") + return errorsmod.Wrap(err, "salt") } return nil } @@ -411,19 +412,19 @@ func (msg MsgUpdateInstantiateConfig) Type() string { func (msg MsgUpdateInstantiateConfig) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { - return sdkerrors.Wrap(err, "sender") + return errorsmod.Wrap(err, "sender") } if msg.CodeID == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "code id is required") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "code id is required") } if msg.NewInstantiatePermission == nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "instantiate permission is required") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "instantiate permission is required") } if err := msg.NewInstantiatePermission.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "instantiate permission") + return errorsmod.Wrap(err, "instantiate permission") } // AccessTypeOnlyAddress is still considered valid as legacy instantiation permission // but not for new contracts diff --git a/x/wasm/types/types.go b/x/wasm/types/types.go index f1c95cf54..5ecdb1906 100644 --- a/x/wasm/types/types.go +++ b/x/wasm/types/types.go @@ -4,6 +4,7 @@ import ( "fmt" "reflect" + errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -24,20 +25,20 @@ const ( func (m Model) ValidateBasic() error { if len(m.Key) == 0 { - return sdkerrors.Wrap(ErrEmpty, "key") + return errorsmod.Wrap(ErrEmpty, "key") } return nil } func (c CodeInfo) ValidateBasic() error { if len(c.CodeHash) == 0 { - return sdkerrors.Wrap(ErrEmpty, "code hash") + return errorsmod.Wrap(ErrEmpty, "code hash") } if _, err := sdk.AccAddressFromBech32(c.Creator); err != nil { - return sdkerrors.Wrap(err, "creator") + return errorsmod.Wrap(err, "creator") } if err := c.InstantiateConfig.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "instantiate config") + return errorsmod.Wrap(err, "instantiate config") } return nil } @@ -78,18 +79,18 @@ type validatable interface { // but also in the genesis import process. func (c *ContractInfo) ValidateBasic() error { if c.CodeID == 0 { - return sdkerrors.Wrap(ErrEmpty, "code id") + return errorsmod.Wrap(ErrEmpty, "code id") } if _, err := sdk.AccAddressFromBech32(c.Creator); err != nil { - return sdkerrors.Wrap(err, "creator") + return errorsmod.Wrap(err, "creator") } if len(c.Admin) != 0 { if _, err := sdk.AccAddressFromBech32(c.Admin); err != nil { - return sdkerrors.Wrap(err, "admin") + return errorsmod.Wrap(err, "admin") } } if err := ValidateLabel(c.Label); err != nil { - return sdkerrors.Wrap(err, "label") + return errorsmod.Wrap(err, "label") } if c.Extension == nil { return nil @@ -100,7 +101,7 @@ func (c *ContractInfo) ValidateBasic() error { return nil } if err := e.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "extension") + return errorsmod.Wrap(err, "extension") } return nil } @@ -119,7 +120,7 @@ func (c *ContractInfo) SetExtension(ext ContractInfoExtension) error { } any, err := codectypes.NewAnyWithValue(ext) if err != nil { - return sdkerrors.Wrap(sdkerrors.ErrPackAny, err.Error()) + return errorsmod.Wrap(sdkerrors.ErrPackAny, err.Error()) } c.Extension = any @@ -131,12 +132,12 @@ func (c *ContractInfo) SetExtension(ext ContractInfoExtension) error { // // var d MyContractDetails // if err := info.ReadExtension(&d); err != nil { -// return nil, sdkerrors.Wrap(err, "extension") +// return nil, errorsmod.Wrap(err, "extension") // } func (c *ContractInfo) ReadExtension(e ContractInfoExtension) error { rv := reflect.ValueOf(e) if rv.Kind() != reflect.Ptr || rv.IsNil() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidType, "not a pointer") + return errorsmod.Wrap(sdkerrors.ErrInvalidType, "not a pointer") } if c.Extension == nil { return nil @@ -145,7 +146,7 @@ func (c *ContractInfo) ReadExtension(e ContractInfoExtension) error { cached := c.Extension.GetCachedValue() elem := reflect.ValueOf(cached).Elem() if !elem.Type().AssignableTo(rv.Elem().Type()) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "extension is of type %s but argument of %s", elem.Type(), rv.Elem().Type()) + return errorsmod.Wrapf(sdkerrors.ErrInvalidType, "extension is of type %s but argument of %s", elem.Type(), rv.Elem().Type()) } rv.Elem().Set(elem) return nil @@ -261,7 +262,7 @@ func (c ContractCodeHistoryEntry) ValidateBasic() error { if c.Updated == nil { return ErrEmpty.Wrap("updated") } - return sdkerrors.Wrap(c.Msg.ValidateBasic(), "msg") + return errorsmod.Wrap(c.Msg.ValidateBasic(), "msg") } // NewEnv initializes the environment for a contract instance diff --git a/x/wasm/types/validation.go b/x/wasm/types/validation.go index 526a6bf55..d3e678ba0 100644 --- a/x/wasm/types/validation.go +++ b/x/wasm/types/validation.go @@ -4,7 +4,7 @@ import ( "fmt" "net/url" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" "github.com/docker/distribution/reference" ) @@ -24,10 +24,10 @@ var ( func validateWasmCode(s []byte, maxSize int) error { if len(s) == 0 { - return sdkerrors.Wrap(ErrEmpty, "is required") + return errorsmod.Wrap(ErrEmpty, "is required") } if len(s) > maxSize { - return sdkerrors.Wrapf(ErrLimit, "cannot be longer than %d bytes", maxSize) + return errorsmod.Wrapf(ErrLimit, "cannot be longer than %d bytes", maxSize) } return nil } @@ -35,7 +35,7 @@ func validateWasmCode(s []byte, maxSize int) error { // ValidateLabel ensure label constraints func ValidateLabel(label string) error { if label == "" { - return sdkerrors.Wrap(ErrEmpty, "is required") + return errorsmod.Wrap(ErrEmpty, "is required") } if len(label) > MaxLabelSize { return ErrLimit.Wrapf("cannot be longer than %d characters", MaxLabelSize) @@ -47,7 +47,7 @@ func ValidateLabel(label string) error { func ValidateSalt(salt []byte) error { switch n := len(salt); { case n == 0: - return sdkerrors.Wrap(ErrEmpty, "is required") + return errorsmod.Wrap(ErrEmpty, "is required") case n > MaxSaltSize: return ErrLimit.Wrapf("cannot be longer than %d characters", MaxSaltSize) }