Skip to content

Commit

Permalink
nit: use getters that guard against a nil pointer. (#6804)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim authored Jul 11, 2024
1 parent 075fc1f commit 1730e94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions modules/apps/transfer/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ func (msg MsgTransfer) validateForwarding() error {

if !msg.TimeoutHeight.IsZero() {
// when forwarding, the timeout height must not be set
return errorsmod.Wrapf(ErrInvalidPacketTimeout, "timeout height must be zero if forwarding path hops is not empty: %s, %s", msg.TimeoutHeight, msg.Forwarding.Hops)
return errorsmod.Wrapf(ErrInvalidPacketTimeout, "timeout height must be zero if forwarding path hops is not empty: %s, %s", msg.TimeoutHeight, msg.Forwarding.GetHops())
}

if msg.Forwarding.Unwind {
if msg.Forwarding.GetUnwind() {
if len(msg.GetCoins()) > 1 {
// When unwinding, we must have at most one token.
return errorsmod.Wrap(ibcerrors.ErrInvalidCoins, "cannot unwind more than one token")
Expand All @@ -154,15 +154,15 @@ func (msg MsgTransfer) HasForwarding() bool {
return false
}

return len(msg.Forwarding.Hops) > 0 || msg.Forwarding.Unwind
return len(msg.Forwarding.GetHops()) > 0 || msg.Forwarding.GetUnwind()
}

// validateIdentifiers validates the source port and channel identifiers based on the
// forwarding information present in the message. If forwarding information is missing
// or unwinding isn't performed, we do normal validation, else, we assert that both
// fields must be empty.
func (msg MsgTransfer) validateIdentifiers() error {
if msg.Forwarding != nil && msg.Forwarding.Unwind {
if msg.Forwarding.GetUnwind() {
if msg.SourcePort != "" {
return errorsmod.Wrapf(ErrInvalidForwarding, "source port must be empty when unwind is set, got %s instead", msg.SourcePort)
}
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/transfer/types/transfer_authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ func validateForwarding(forwarding *Forwarding, allowedForwarding []AllowedForwa
return nil
}

if forwarding.Unwind {
if forwarding.GetUnwind() {
return errorsmod.Wrap(ErrInvalidForwarding, "not allowed automatic unwind")
}

if !isAllowedForwarding(forwarding.Hops, allowedForwarding) {
if !isAllowedForwarding(forwarding.GetHops(), allowedForwarding) {
return errorsmod.Wrapf(ErrInvalidForwarding, "not allowed hops %s", forwarding.Hops)
}

Expand Down

0 comments on commit 1730e94

Please sign in to comment.