diff --git a/modules/apps/transfer/ibc_module.go b/modules/apps/transfer/ibc_module.go index f611c62642f..2639273b701 100644 --- a/modules/apps/transfer/ibc_module.go +++ b/modules/apps/transfer/ibc_module.go @@ -184,6 +184,8 @@ func (im IBCModule) OnRecvPacket( if err != nil { ack = types.NewErrorAcknowledgement(err) } + + im.keeper.AfterOnRecvPacket(ctx, data) } ctx.EventManager().EmitEvent( @@ -222,6 +224,10 @@ func (im IBCModule) OnAcknowledgementPacket( return err } + // AfterTransferEnd + denom := types.ParseDenomTrace(data.Denom) + im.keeper.AfterTransferEnd(ctx, data, denom.BaseDenom) + ctx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypePacket, diff --git a/modules/apps/transfer/keeper/hooks.go b/modules/apps/transfer/keeper/hooks.go index 50f1877638b..3900c1206f8 100644 --- a/modules/apps/transfer/keeper/hooks.go +++ b/modules/apps/transfer/keeper/hooks.go @@ -5,7 +5,12 @@ import ( "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" ) -// AfterEpochEnd executes the indicated hook after epochs ends +// AfterEpochEnd executes the indicated hook after Transfer ends func (k Keeper) AfterTransferEnd(ctx sdk.Context, packet types.FungibleTokenPacketData, base_denom string) { k.hooks.AfterTransferEnd(ctx, packet, base_denom) } + +// AfterOnRecvPacket executes the indicated hook after OnRecvPacket ends +func (k Keeper) AfterOnRecvPacket(ctx sdk.Context, packet types.FungibleTokenPacketData) { + k.hooks.AfterOnRecvPacket(ctx, packet) +} diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index a12d1e79207..888fdc8cdfd 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -48,6 +48,8 @@ import ( // 4. A -> C : sender chain is sink zone. Denom upon receiving: 'C/B/denom' // 5. C -> B : sender chain is sink zone. Denom upon receiving: 'B/denom' // 6. B -> A : sender chain is sink zone. Denom upon receiving: 'denom' + +// nova - func (k Keeper) SendTransfer( ctx sdk.Context, sourcePort, @@ -88,12 +90,15 @@ func (k Keeper) SendTransfer( } // NOTE: denomination and hex hash correctness checked during msg.ValidateBasic + // uatom fullDenomPath := token.Denom var err error // deconstruct the token denomination into the denomination trace info // to determine if the sender is the source chain + // uatom -> osmo -> nova + // ibc/hash if strings.HasPrefix(token.Denom, "ibc/") { fullDenomPath, err = k.DenomPathFromHash(ctx, token.Denom) if err != nil { @@ -122,7 +127,6 @@ func (k Keeper) SendTransfer( ); err != nil { return err } - } else { labels = append(labels, telemetry.NewLabel(coretypes.LabelSource, "false")) @@ -243,6 +247,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", receiver) } + // portID/channelID/basedenom // unescrow tokens escrowAddress := types.GetEscrowAddress(packet.GetDestPort(), packet.GetDestChannel()) if err := k.bankKeeper.SendCoins(ctx, escrowAddress, receiver, sdk.NewCoins(token)); err != nil { @@ -270,7 +275,6 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t ), ) }() - return nil } @@ -313,6 +317,9 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t return err } + // hook 실행 + // k.AfterOnRecvPacket(ctx, packet) + defer func() { if transferAmount.IsInt64() { telemetry.SetGaugeWithLabels( @@ -345,10 +352,6 @@ func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Pac default: // the acknowledgement succeeded on the receiving chain so nothing // needs to be executed and no error needs to be returned - - //TODO : add filter - denom := types.ParseDenomTrace(data.Denom) - k.AfterTransferEnd(ctx, data, denom.BaseDenom) return nil } } diff --git a/modules/apps/transfer/types/hooks.go b/modules/apps/transfer/types/hooks.go index f1dc32b955f..f1e7cbfbf3e 100644 --- a/modules/apps/transfer/types/hooks.go +++ b/modules/apps/transfer/types/hooks.go @@ -6,6 +6,7 @@ import ( type TransferHooks interface { AfterTransferEnd(ctx sdk.Context, data FungibleTokenPacketData, base_denom string) + AfterOnRecvPacket(ctx sdk.Context, data FungibleTokenPacketData) } var _ TransferHooks = MultiTransferHooks{} @@ -21,3 +22,9 @@ func (h MultiTransferHooks) AfterTransferEnd(ctx sdk.Context, data FungibleToken h[i].AfterTransferEnd(ctx, data, base_denom) } } + +func (h MultiTransferHooks) AfterOnRecvPacket(ctx sdk.Context, data FungibleTokenPacketData) { + for i := range h { + h[i].AfterOnRecvPacket(ctx, data) + } +}