Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Change ErrDuplicateEntry to ErrInvalidAuthorization & change error formatting #2988

Merged
merged 8 commits into from
Jan 9, 2023
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