-
Notifications
You must be signed in to change notification settings - Fork 2
/
events.go
77 lines (69 loc) · 2.89 KB
/
events.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package keeper
import (
"fmt"
sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
"github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/29-fee/types"
channeltypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/04-channel/types"
)
// EmitIncentivizedPacketEvent emits an event containing information on the total amount of fees incentivizing
// a specific packet. It should be emitted on every fee escrowed for the given packetID.
func EmitIncentivizedPacketEvent(ctx sdk.Context, packetID channeltypes.PacketId, packetFees types.PacketFees) {
var (
totalRecvFees sdk.CoinAdapters
totalAckFees sdk.CoinAdapters
totalTimeoutFees sdk.CoinAdapters
)
for _, fee := range packetFees.PacketFees {
// only emit total fees for packet fees which allow any relayer to relay
if fee.Relayers == nil {
totalRecvFees = totalRecvFees.Add(fee.Fee.RecvFee...)
totalAckFees = totalAckFees.Add(fee.Fee.AckFee...)
totalTimeoutFees = totalTimeoutFees.Add(fee.Fee.TimeoutFee...)
}
}
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeIncentivizedPacket,
sdk.NewAttribute(channeltypes.AttributeKeyPortID, packetID.PortId),
sdk.NewAttribute(channeltypes.AttributeKeyChannelID, packetID.ChannelId),
sdk.NewAttribute(channeltypes.AttributeKeySequence, fmt.Sprint(packetID.Sequence)),
sdk.NewAttribute(types.AttributeKeyRecvFee, totalRecvFees.String()),
sdk.NewAttribute(types.AttributeKeyAckFee, totalAckFees.String()),
sdk.NewAttribute(types.AttributeKeyTimeoutFee, totalTimeoutFees.String()),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
),
})
}
// EmitRegisterPayeeEvent emits an event containing information of a registered payee for a relayer on a particular channel
func EmitRegisterPayeeEvent(ctx sdk.Context, relayer, payee, channelID string) {
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeRegisterPayee,
sdk.NewAttribute(types.AttributeKeyRelayer, relayer),
sdk.NewAttribute(types.AttributeKeyPayee, payee),
sdk.NewAttribute(types.AttributeKeyChannelID, channelID),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
),
})
}
// EmitRegisterCounterpartyPayeeEvent emits an event containing information of a registered counterparty payee for a relayer on a particular channel
func EmitRegisterCounterpartyPayeeEvent(ctx sdk.Context, relayer, counterpartyPayee, channelID string) {
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeRegisterCounterpartyPayee,
sdk.NewAttribute(types.AttributeKeyRelayer, relayer),
sdk.NewAttribute(types.AttributeKeyCounterpartyPayee, counterpartyPayee),
sdk.NewAttribute(types.AttributeKeyChannelID, channelID),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
),
})
}