From d8b982127214617f139bda8c2d1ce5fd43685d7a Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 17 Feb 2022 16:31:23 +0100 Subject: [PATCH] ics29:feat: emit event escrow (#914) * feat: emit EventTypeSendIncentivizedPacket event on EscrowPacket * fix: string conversion * refactor: add helper fn for emit event * chore: godoc * nit: use .String()) --- modules/apps/29-fee/keeper/escrow.go | 2 ++ modules/apps/29-fee/keeper/events.go | 25 +++++++++++++++++++++++++ modules/apps/29-fee/types/events.go | 4 +++- modules/apps/29-fee/types/keys.go | 4 ++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 modules/apps/29-fee/keeper/events.go diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index e97096271b7..1d0aa60c74f 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -39,6 +39,8 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, identifiedFee types.IdentifiedP identifiedFees := types.NewIdentifiedPacketFees(packetFees) k.SetFeesInEscrow(ctx, identifiedFee.PacketId, identifiedFees) + EmitIncentivizedPacket(ctx, identifiedFee) + return nil } diff --git a/modules/apps/29-fee/keeper/events.go b/modules/apps/29-fee/keeper/events.go new file mode 100644 index 00000000000..64c44a34ea0 --- /dev/null +++ b/modules/apps/29-fee/keeper/events.go @@ -0,0 +1,25 @@ +package keeper + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" + channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" +) + +// EmitIncentivizedPacket emits an event so that relayers know an incentivized packet is ready to be relayed +func EmitIncentivizedPacket(ctx sdk.Context, identifiedFee types.IdentifiedPacketFee) { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeIncentivizedPacket, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, identifiedFee.PacketId.PortId), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, identifiedFee.PacketId.ChannelId), + sdk.NewAttribute(channeltypes.AttributeKeySequence, fmt.Sprint(identifiedFee.PacketId.Sequence)), + sdk.NewAttribute(types.AttributeKeyRecvFee, identifiedFee.Fee.RecvFee.String()), + sdk.NewAttribute(types.AttributeKeyAckFee, identifiedFee.Fee.AckFee.String()), + sdk.NewAttribute(types.AttributeKeyTimeoutFee, identifiedFee.Fee.TimeoutFee.String()), + ), + ) +} diff --git a/modules/apps/29-fee/types/events.go b/modules/apps/29-fee/types/events.go index 4b8d5ee8c95..2c63bc0dcc8 100644 --- a/modules/apps/29-fee/types/events.go +++ b/modules/apps/29-fee/types/events.go @@ -1,4 +1,6 @@ package types // 29-fee events -const () +const ( + EventTypeIncentivizedPacket = "incentivized_ibc_packet" +) diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index b13aa2ba4b8..ec5132fab1a 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -35,6 +35,10 @@ const ( // ForwardRelayerPrefix is the key prefix for forward relayer addresses stored in state for async acknowledgements ForwardRelayerPrefix = "forwardRelayer" + + AttributeKeyRecvFee = "recv_fee" + AttributeKeyAckFee = "ack_fee" + AttributeKeyTimeoutFee = "timeout_fee" ) // FeeEnabledKey returns the key that stores a flag to determine if fee logic should