@@ -10,6 +10,33 @@ import (
10
10
"github.com/cosmos/ibc-go/modules/core/exported"
11
11
)
12
12
13
+ // EmitSendPacketEvent emits an event with packet data along with other packet information for relayer
14
+ // to pick up and relay to other chain
15
+ func EmitSendPacketEvent (ctx sdk.Context , packet exported.PacketI , channel types.Channel , timeoutHeight exported.Height ) {
16
+ ctx .EventManager ().EmitEvents (sdk.Events {
17
+ sdk .NewEvent (
18
+ types .EventTypeSendPacket ,
19
+ sdk .NewAttribute (types .AttributeKeyData , string (packet .GetData ())), // DEPRECATED
20
+ sdk .NewAttribute (types .AttributeKeyDataHex , hex .EncodeToString (packet .GetData ())),
21
+ sdk .NewAttribute (types .AttributeKeyTimeoutHeight , timeoutHeight .String ()),
22
+ sdk .NewAttribute (types .AttributeKeyTimeoutTimestamp , fmt .Sprintf ("%d" , packet .GetTimeoutTimestamp ())),
23
+ sdk .NewAttribute (types .AttributeKeySequence , fmt .Sprintf ("%d" , packet .GetSequence ())),
24
+ sdk .NewAttribute (types .AttributeKeySrcPort , packet .GetSourcePort ()),
25
+ sdk .NewAttribute (types .AttributeKeySrcChannel , packet .GetSourceChannel ()),
26
+ sdk .NewAttribute (types .AttributeKeyDstPort , packet .GetDestPort ()),
27
+ sdk .NewAttribute (types .AttributeKeyDstChannel , packet .GetDestChannel ()),
28
+ sdk .NewAttribute (types .AttributeKeyChannelOrdering , channel .Ordering .String ()),
29
+ // we only support 1-hop packets now, and that is the most important hop for a relayer
30
+ // (is it going to a chain I am connected to)
31
+ sdk .NewAttribute (types .AttributeKeyConnection , channel .ConnectionHops [0 ]),
32
+ ),
33
+ sdk .NewEvent (
34
+ sdk .EventTypeMessage ,
35
+ sdk .NewAttribute (sdk .AttributeKeyModule , types .AttributeValueCategory ),
36
+ ),
37
+ })
38
+ }
39
+
13
40
// EmitRecvPacketEvent emits a receive packet event. It will be emitted both the first time a packet
14
41
// is received for a certain sequence and for all duplicate receives.
15
42
func EmitRecvPacketEvent (ctx sdk.Context , packet exported.PacketI , channel types.Channel ) {
@@ -37,6 +64,33 @@ func EmitRecvPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types
37
64
})
38
65
}
39
66
67
+ // EmitWriteAcknowledgementEvent emits an event that the relayer can query for
68
+ func EmitWriteAcknowledgementEvent (ctx sdk.Context , packet exported.PacketI , channel types.Channel , acknowledgement []byte ) {
69
+ ctx .EventManager ().EmitEvents (sdk.Events {
70
+ sdk .NewEvent (
71
+ types .EventTypeWriteAck ,
72
+ sdk .NewAttribute (types .AttributeKeyData , string (packet .GetData ())), // DEPRECATED
73
+ sdk .NewAttribute (types .AttributeKeyDataHex , hex .EncodeToString (packet .GetData ())),
74
+ sdk .NewAttribute (types .AttributeKeyTimeoutHeight , packet .GetTimeoutHeight ().String ()),
75
+ sdk .NewAttribute (types .AttributeKeyTimeoutTimestamp , fmt .Sprintf ("%d" , packet .GetTimeoutTimestamp ())),
76
+ sdk .NewAttribute (types .AttributeKeySequence , fmt .Sprintf ("%d" , packet .GetSequence ())),
77
+ sdk .NewAttribute (types .AttributeKeySrcPort , packet .GetSourcePort ()),
78
+ sdk .NewAttribute (types .AttributeKeySrcChannel , packet .GetSourceChannel ()),
79
+ sdk .NewAttribute (types .AttributeKeyDstPort , packet .GetDestPort ()),
80
+ sdk .NewAttribute (types .AttributeKeyDstChannel , packet .GetDestChannel ()),
81
+ sdk .NewAttribute (types .AttributeKeyAck , string (acknowledgement )),
82
+ sdk .NewAttribute (types .AttributeKeyAckHex , hex .EncodeToString (acknowledgement )),
83
+ // we only support 1-hop packets now, and that is the most important hop for a relayer
84
+ // (is it going to a chain I am connected to)
85
+ sdk .NewAttribute (types .AttributeKeyConnection , channel .ConnectionHops [0 ]),
86
+ ),
87
+ sdk .NewEvent (
88
+ sdk .EventTypeMessage ,
89
+ sdk .NewAttribute (sdk .AttributeKeyModule , types .AttributeValueCategory ),
90
+ ),
91
+ })
92
+ }
93
+
40
94
// EmitAcknowledgePacketEvent emits an acknowledge packet event. It will be emitted both the first time
41
95
// a packet is acknowledged for a certain sequence and for all duplicate acknowledgements.
42
96
func EmitAcknowledgePacketEvent (ctx sdk.Context , packet exported.PacketI , channel types.Channel ) {
0 commit comments