Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace deprecated Wrap and Wrapf #1278

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions x/dymns/client/cli/tx_update_resolve_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"time"

"cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down Expand Up @@ -43,14 +43,14 @@ func NewUpdateResolveDymNameAddressTxCmd() *cobra.Command {

subName, dymName, chainIdOrAlias, err := dymnskeeper.ParseDymNameAddress(dymNameAddress)
if err != nil {
return errors.Wrap(err, "failed to parse input Dym-Name-Address")
return errorsmod.Wrap(err, "failed to parse input Dym-Name-Address")
}

respTranslateChainId, err := queryClient.TranslateAliasOrChainIdToChainId(cmd.Context(), &dymnstypes.QueryTranslateAliasOrChainIdToChainIdRequest{
AliasOrChainId: chainIdOrAlias,
})
if err != nil || respTranslateChainId.ChainId == "" {
return errors.Wrapf(err, "failed to translate alias to chain-id: %s", chainIdOrAlias)
return errorsmod.Wrapf(err, "failed to translate alias to chain-id: %s", chainIdOrAlias)
}

chainId := respTranslateChainId.ChainId
Expand Down
26 changes: 14 additions & 12 deletions x/lockup/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +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"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -42,7 +44,7 @@ func (q Querier) AccountUnlockableCoins(goCtx context.Context, req *types.Accoun
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -61,7 +63,7 @@ func (q Querier) AccountUnlockingCoins(goCtx context.Context, req *types.Account
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -80,7 +82,7 @@ func (q Querier) AccountLockedCoins(goCtx context.Context, req *types.AccountLoc
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -99,7 +101,7 @@ func (q Querier) AccountLockedPastTime(goCtx context.Context, req *types.Account
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -118,7 +120,7 @@ func (q Querier) AccountUnlockedBeforeTime(goCtx context.Context, req *types.Acc
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -138,7 +140,7 @@ func (q Querier) AccountLockedPastTimeDenom(goCtx context.Context, req *types.Ac
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand Down Expand Up @@ -181,7 +183,7 @@ func (q Querier) AccountLockedLongerDuration(goCtx context.Context, req *types.A
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -201,7 +203,7 @@ func (q Querier) AccountLockedLongerDurationDenom(goCtx context.Context, req *ty
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -221,7 +223,7 @@ func (q Querier) AccountLockedDuration(goCtx context.Context, req *types.Account
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -242,7 +244,7 @@ func (q Querier) AccountLockedPastTimeNotUnlockingOnly(goCtx context.Context, re
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -262,7 +264,7 @@ func (q Querier) AccountLockedLongerDurationNotUnlockingOnly(goCtx context.Conte
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -281,7 +283,7 @@ func (q Querier) LockedDenom(goCtx context.Context, req *types.LockedDenomReques
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Denom) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty denom")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty denom")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand Down
6 changes: 4 additions & 2 deletions x/lockup/keeper/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"sort"
"time"

errorsmod "cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -55,15 +57,15 @@ func (k Keeper) AddToExistingLock(ctx sdk.Context, owner sdk.AccAddress, coin sd

// if no lock exists for the given owner + denom + duration, return an error
if len(locks) < 1 {
return 0, sdkerrors.Wrapf(types.ErrLockupNotFound, "lock with denom %s before duration %s does not exist", coin.Denom, duration.String())
return 0, errorsmod.Wrapf(types.ErrLockupNotFound, "lock with denom %s before duration %s does not exist", coin.Denom, duration.String())
}

// if existing lock with same duration and denom exists, add to the existing lock
// there should only be a single lock with the same duration + token, thus we take the first lock
lock := locks[0]
_, err := k.AddTokensToLockByID(ctx, lock.ID, owner, coin)
if err != nil {
return 0, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, err.Error())
return 0, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, err.Error())
}

return lock.ID, nil
Expand Down
24 changes: 13 additions & 11 deletions x/lockup/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/osmosis-labs/osmosis/v15/osmoutils"
Expand Down Expand Up @@ -60,7 +62,7 @@ func (server msgServer) LockTokens(goCtx context.Context, msg *types.MsgLockToke
// if the owner + duration combination is new, create a new lock.
lock, err := server.keeper.CreateLock(ctx, owner, msg.Coins, msg.Duration)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
}

ctx.EventManager().EmitEvents(sdk.Events{
Expand All @@ -84,16 +86,16 @@ func (server msgServer) BeginUnlocking(goCtx context.Context, msg *types.MsgBegi

lock, err := server.keeper.GetLockByID(ctx, msg.ID)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
}

if msg.Owner != lock.Owner {
return nil, sdkerrors.Wrap(types.ErrNotLockOwner, fmt.Sprintf("msg sender (%s) and lock owner (%s) does not match", msg.Owner, lock.Owner))
return nil, errorsmod.Wrap(types.ErrNotLockOwner, fmt.Sprintf("msg sender (%s) and lock owner (%s) does not match", msg.Owner, lock.Owner))
}

unlockingLock, err := server.keeper.BeginUnlock(ctx, lock.ID, msg.Coins)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
}

// N.B. begin unlock event is emitted downstream in the keeper method.
Expand All @@ -112,7 +114,7 @@ func (server msgServer) BeginUnlockingAll(goCtx context.Context, msg *types.MsgB

unlocks, err := server.keeper.BeginUnlockAllNotUnlockings(ctx, owner)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
}

// Create the events for this message
Expand Down Expand Up @@ -156,12 +158,12 @@ func (server msgServer) ExtendLockup(goCtx context.Context, msg *types.MsgExtend

err = server.keeper.ExtendLockup(ctx, msg.ID, owner, msg.Duration)
if err != nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, err.Error())
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, err.Error())
}

lock, err := server.keeper.GetLockByID(ctx, msg.ID)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
}

ctx.EventManager().EmitEvents(sdk.Events{
Expand All @@ -184,12 +186,12 @@ func (server msgServer) ForceUnlock(goCtx context.Context, msg *types.MsgForceUn

lock, err := server.keeper.GetLockByID(ctx, msg.ID)
if err != nil {
return &types.MsgForceUnlockResponse{Success: false}, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
return &types.MsgForceUnlockResponse{Success: false}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
}

// check if message sender matches lock owner
if lock.Owner != msg.Owner {
return &types.MsgForceUnlockResponse{Success: false}, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "Sender (%s) does not match lock owner (%s)", msg.Owner, lock.Owner)
return &types.MsgForceUnlockResponse{Success: false}, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "Sender (%s) does not match lock owner (%s)", msg.Owner, lock.Owner)
}

// check for chain parameter that the address is allowed to force unlock
Expand All @@ -203,15 +205,15 @@ func (server msgServer) ForceUnlock(goCtx context.Context, msg *types.MsgForceUn
}
}
if !found {
return &types.MsgForceUnlockResponse{Success: false}, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "Sender (%s) not allowed to force unlock", lock.Owner)
return &types.MsgForceUnlockResponse{Success: false}, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "Sender (%s) not allowed to force unlock", lock.Owner)
}

// force unlock given lock
// This also supports the case of force unlocking lock as a whole when msg.Coins
// provided is empty.
err = server.keeper.PartialForceUnlock(ctx, *lock, msg.Coins)
if err != nil {
return &types.MsgForceUnlockResponse{Success: false}, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
return &types.MsgForceUnlockResponse{Success: false}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
}

return &types.MsgForceUnlockResponse{Success: true}, nil
Expand Down
5 changes: 3 additions & 2 deletions x/lockup/keeper/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"fmt"
"time"

errorsmod "cosmossdk.io/errors"

keruch marked this conversation as resolved.
Show resolved Hide resolved
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/gogoproto/proto"

"github.com/dymensionxyz/dymension/v3/x/lockup/types"
Expand Down Expand Up @@ -226,7 +227,7 @@ func (k Keeper) GetLockByID(ctx sdk.Context, lockID uint64) (*types.PeriodLock,
store := ctx.KVStore(k.storeKey)
lockKey := lockStoreKey(lockID)
if !store.Has(lockKey) {
return nil, sdkerrors.Wrap(types.ErrLockupNotFound, fmt.Sprintf("lock with ID %d does not exist", lockID))
return nil, errorsmod.Wrap(types.ErrLockupNotFound, fmt.Sprintf("lock with ID %d does not exist", lockID))
}
bz := store.Get(lockKey)
err := proto.Unmarshal(bz, &lock)
Expand Down
16 changes: 9 additions & 7 deletions x/lockup/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"time"

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -32,7 +34,7 @@ func (m MsgLockTokens) Type() string { return TypeMsgLockTokens }
func (m MsgLockTokens) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.Owner)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
}

if m.Duration <= 0 {
Expand Down Expand Up @@ -74,7 +76,7 @@ func (m MsgBeginUnlockingAll) Type() string { return TypeMsgBeginUnlockingAll }
func (m MsgBeginUnlockingAll) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.Owner)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
}
return nil
}
Expand Down Expand Up @@ -104,7 +106,7 @@ func (m MsgBeginUnlocking) Type() string { return TypeMsgBeginUnlocking }
func (m MsgBeginUnlocking) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.Owner)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
}

if m.ID == 0 {
Expand Down Expand Up @@ -146,7 +148,7 @@ func (m MsgExtendLockup) Type() string { return TypeMsgExtendLockup }
func (m MsgExtendLockup) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.Owner)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
}
if m.ID == 0 {
return fmt.Errorf("id is empty")
Expand Down Expand Up @@ -182,15 +184,15 @@ func (m MsgForceUnlock) Type() string { return TypeMsgBeginUnlockingAll }
func (m MsgForceUnlock) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.Owner)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
}

if m.ID <= 0 {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "lock id should be bigger than 1 (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "lock id should be bigger than 1 (%s)", err)
}

if !m.Coins.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, m.Coins.String())
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, m.Coins.String())
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions x/sequencer/keeper/rotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"sort"
"time"

"cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/dymension/v3/x/sequencer/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
Expand Down Expand Up @@ -111,11 +111,11 @@ func (k Keeper) startRotation(ctx sdk.Context, rollappId string) {
func (k Keeper) CompleteRotation(ctx sdk.Context, rollappId string) error {
proposer, ok := k.GetProposer(ctx, rollappId)
if !ok {
return errors.Wrapf(gerrc.ErrInternal, "proposer not set for rollapp %s", rollappId)
return errorsmod.Wrapf(gerrc.ErrInternal, "proposer not set for rollapp %s", rollappId)
}
nextProposer, ok := k.GetNextProposer(ctx, rollappId)
if !ok {
return errors.Wrapf(gerrc.ErrInternal, "next proposer not set for rollapp %s", rollappId)
return errorsmod.Wrapf(gerrc.ErrInternal, "next proposer not set for rollapp %s", rollappId)
}

// start unbonding the current proposer
Expand Down