Skip to content

Commit

Permalink
Change ErrDuplicateEntry to ErrInvalidAuthorization & change error fo…
Browse files Browse the repository at this point in the history
…rmatting (#2988)
  • Loading branch information
chatton authored Jan 9, 2023
1 parent 3ffc225 commit 9a2fe70
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion modules/apps/transfer/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ var (
ErrSendDisabled = sdkerrors.Register(ModuleName, 7, "fungible token transfers from this chain are disabled")
ErrReceiveDisabled = sdkerrors.Register(ModuleName, 8, "fungible token transfers to this chain are disabled")
ErrMaxTransferChannels = sdkerrors.Register(ModuleName, 9, "max transfer channels")
ErrDuplicateEntry = sdkerrors.Register(ModuleName, 10, "duplicated entry")
ErrInvalidAuthorization = sdkerrors.Register(ModuleName, 10, "invalid transfer authorization")
)
12 changes: 6 additions & 6 deletions modules/apps/transfer/types/transfer_authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ func (a TransferAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.Accep
if allocation.SourceChannel == msgTransfer.SourceChannel && allocation.SourcePort == msgTransfer.SourcePort {
limitLeft, isNegative := allocation.SpendLimit.SafeSub(msgTransfer.Token)
if isNegative {
return authz.AcceptResponse{}, sdkerrors.ErrInsufficientFunds.Wrapf("requested amount is more than spend limit")
return authz.AcceptResponse{}, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "requested amount is more than spend limit")
}

if !isAllowedAddress(ctx, msgTransfer.Receiver, allocation.AllowedAddresses) {
return authz.AcceptResponse{}, sdkerrors.ErrInvalidAddress.Wrapf("not allowed address for transfer")
return authz.AcceptResponse{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "not allowed address for transfer")
}

if limitLeft.IsZero() {
Expand All @@ -74,17 +74,17 @@ func (a TransferAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.Accep
}}, nil
}
}
return authz.AcceptResponse{}, sdkerrors.ErrNotFound.Wrapf("requested port and channel allocation does not exist")
return authz.AcceptResponse{}, sdkerrors.Wrapf(sdkerrors.ErrNotFound, "requested port and channel allocation does not exist")
}

// ValidateBasic implements Authorization.ValidateBasic.
func (a TransferAuthorization) ValidateBasic() error {
for _, allocation := range a.Allocations {
if allocation.SpendLimit == nil {
return sdkerrors.ErrInvalidCoins.Wrap("spend limit cannot be nil")
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "spend limit cannot be nil")
}
if err := allocation.SpendLimit.Validate(); err != nil {
return sdkerrors.ErrInvalidCoins.Wrapf(err.Error())
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, err.Error())
}
if err := host.PortIdentifierValidator(allocation.SourcePort); err != nil {
return sdkerrors.Wrap(err, "invalid source port ID")
Expand All @@ -96,7 +96,7 @@ func (a TransferAuthorization) ValidateBasic() error {
found := make(map[string]bool, 0)
for i := 0; i < len(allocation.AllowedAddresses); i++ {
if found[allocation.AllowedAddresses[i]] {
return ErrDuplicateEntry
return sdkerrors.Wrapf(ErrInvalidAuthorization, "duplicate entry in allow list %s")
}
found[allocation.AllowedAddresses[i]] = true
}
Expand Down

0 comments on commit 9a2fe70

Please sign in to comment.