From 0f5ffe5b132cbd6e15ab22c19debfe94ffb7b899 Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 15 Feb 2022 17:09:13 +0100 Subject: [PATCH] refactor: add helper fn for emit event --- modules/apps/29-fee/keeper/escrow.go | 11 +---------- modules/apps/29-fee/keeper/events.go | 24 ++++++++++++++++++++++++ modules/apps/29-fee/types/events.go | 2 +- modules/apps/29-fee/types/keys.go | 4 ++++ 4 files changed, 30 insertions(+), 11 deletions(-) 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 12dacb035a6..a462b395ef9 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -7,7 +7,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" - channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ) // EscrowPacketFee sends the packet fee to the 29-fee module account to hold in escrow @@ -40,15 +39,7 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, identifiedFee types.IdentifiedP // Store fee in state for reference later k.SetFeeInEscrow(ctx, identifiedFee) - // Emit event so that relayers know an incentivized packet is ready to be relayed - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeSendIncentivizedPacket, - sdk.NewAttribute(channeltypes.AttributeKeyPortID, identifiedFee.PacketId.PortId), - sdk.NewAttribute(channeltypes.AttributeKeyChannelID, identifiedFee.PacketId.ChannelId), - sdk.NewAttribute(channeltypes.AttributeKeySequence, fmt.Sprint(identifiedFee.PacketId.Sequence)), - ), - ) + 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..a8d8e264942 --- /dev/null +++ b/modules/apps/29-fee/keeper/events.go @@ -0,0 +1,24 @@ +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" +) + +// Emit 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, fmt.Sprint(identifiedFee.Fee.RecvFee)), + sdk.NewAttribute(types.AttributeKeyAckFee, fmt.Sprint(identifiedFee.Fee.AckFee)), + sdk.NewAttribute(types.AttributeKeyTimeoutFee, fmt.Sprint(identifiedFee.Fee.TimeoutFee)), + ), + ) +} diff --git a/modules/apps/29-fee/types/events.go b/modules/apps/29-fee/types/events.go index e3d010c4a93..2c63bc0dcc8 100644 --- a/modules/apps/29-fee/types/events.go +++ b/modules/apps/29-fee/types/events.go @@ -2,5 +2,5 @@ package types // 29-fee events const ( - EventTypeSendIncentivizedPacket = "send_incentivized_packet" + EventTypeIncentivizedPacket = "incentivized_ibc_packet" ) diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 2f26b859afc..a390a6ece33 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -32,6 +32,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