Skip to content

Commit

Permalink
refactor: add helper fn for emit event
Browse files Browse the repository at this point in the history
  • Loading branch information
seantking committed Feb 15, 2022
1 parent 1c5e749 commit 0f5ffe5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
11 changes: 1 addition & 10 deletions modules/apps/29-fee/keeper/escrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
24 changes: 24 additions & 0 deletions modules/apps/29-fee/keeper/events.go
Original file line number Diff line number Diff line change
@@ -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)),
),
)
}
2 changes: 1 addition & 1 deletion modules/apps/29-fee/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package types

// 29-fee events
const (
EventTypeSendIncentivizedPacket = "send_incentivized_packet"
EventTypeIncentivizedPacket = "incentivized_ibc_packet"
)
4 changes: 4 additions & 0 deletions modules/apps/29-fee/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0f5ffe5

Please sign in to comment.