Skip to content

Commit

Permalink
chore: replace continue with if/else (#6700)
Browse files Browse the repository at this point in the history
Co-authored-by: Nikolas De Giorgis <nikolas.degiorgis@interchain.io>
  • Loading branch information
crodriguezvega and bznein authored Jun 26, 2024
1 parent 100ccc7 commit 13d3ac6
Showing 1 changed file with 37 additions and 40 deletions.
77 changes: 37 additions & 40 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,56 +228,53 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t

// Appending token. The new denom has been computed
receivedCoins = append(receivedCoins, coin)
} else {
// sender chain is the source, mint vouchers

// Continue processing rest of tokens in packet data.
continue
}
// since SendPacket did not prefix the denomination, we must add the destination port and channel to the trace
trace := []types.Trace{types.NewTrace(packet.DestinationPort, packet.DestinationChannel)}
token.Denom.Trace = append(trace, token.Denom.Trace...)

// sender chain is the source, mint vouchers
if !k.HasDenom(ctx, token.Denom.Hash()) {
k.SetDenom(ctx, token.Denom)
}

// since SendPacket did not prefix the denomination, we must add the destination port and channel to the trace
trace := []types.Trace{types.NewTrace(packet.DestinationPort, packet.DestinationChannel)}
token.Denom.Trace = append(trace, token.Denom.Trace...)
voucherDenom := token.Denom.IBCDenom()
if !k.bankKeeper.HasDenomMetaData(ctx, voucherDenom) {
k.setDenomMetadata(ctx, token.Denom)
}

if !k.HasDenom(ctx, token.Denom.Hash()) {
k.SetDenom(ctx, token.Denom)
}
events.EmitDenomEvent(ctx, token)

voucherDenom := token.Denom.IBCDenom()
if !k.bankKeeper.HasDenomMetaData(ctx, voucherDenom) {
k.setDenomMetadata(ctx, token.Denom)
}
voucher := sdk.NewCoin(voucherDenom, transferAmount)

events.EmitDenomEvent(ctx, token)
// mint new tokens if the source of the transfer is the same chain
if err := k.bankKeeper.MintCoins(
ctx, types.ModuleName, sdk.NewCoins(voucher),
); err != nil {
return errorsmod.Wrap(err, "failed to mint IBC tokens")
}

voucher := sdk.NewCoin(voucherDenom, transferAmount)
// send to receiver
if k.IsBlockedAddr(receiver) {
return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to receive funds", receiver)
}
moduleAddr := k.authKeeper.GetModuleAddress(types.ModuleName)
if moduleAddr == nil {
return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", types.ModuleName)
}
if err := k.bankKeeper.SendCoins(
ctx, moduleAddr, receiver, sdk.NewCoins(voucher),
); err != nil {
return errorsmod.Wrapf(err, "failed to send coins to receiver %s", receiver.String())
}

// mint new tokens if the source of the transfer is the same chain
if err := k.bankKeeper.MintCoins(
ctx, types.ModuleName, sdk.NewCoins(voucher),
); err != nil {
return errorsmod.Wrap(err, "failed to mint IBC tokens")
}
denomPath := token.Denom.Path()
labels = append(labels, telemetry.NewLabel(coretypes.LabelSource, "false"))
defer internaltelemetry.ReportOnRecvPacketTelemetry(transferAmount, denomPath, labels)

// send to receiver
if k.IsBlockedAddr(receiver) {
return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to receive funds", receiver)
}
moduleAddr := k.authKeeper.GetModuleAddress(types.ModuleName)
if moduleAddr == nil {
return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", types.ModuleName)
}
if err := k.bankKeeper.SendCoins(
ctx, moduleAddr, receiver, sdk.NewCoins(voucher),
); err != nil {
return errorsmod.Wrapf(err, "failed to send coins to receiver %s", receiver.String())
receivedCoins = append(receivedCoins, voucher)
}

denomPath := token.Denom.Path()
labels = append(labels, telemetry.NewLabel(coretypes.LabelSource, "false"))
defer internaltelemetry.ReportOnRecvPacketTelemetry(transferAmount, denomPath, labels)

receivedCoins = append(receivedCoins, voucher)
}

if data.ShouldBeForwarded() {
Expand Down

0 comments on commit 13d3ac6

Please sign in to comment.