-
Notifications
You must be signed in to change notification settings - Fork 625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created helper functions for emitting packet events #343
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,3 +83,57 @@ func EmitTimeoutPacketEvent(ctx sdk.Context, packet exported.PacketI, channel ty | |
), | ||
}) | ||
} | ||
|
||
// EmitSendPacketEvent emits an vent with Packet data along with other packet information for relayer | ||
// to pick up and relay to other chain | ||
func EmitSendPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel, timeoutHeight exported.Height) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move this function to the top of the file, just before |
||
ctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
types.EventTypeSendPacket, | ||
sdk.NewAttribute(types.AttributeKeyData, string(packet.GetData())), // DEPRECATED | ||
sdk.NewAttribute(types.AttributeKeyDataHex, hex.EncodeToString(packet.GetData())), | ||
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, timeoutHeight.String()), | ||
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())), | ||
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())), | ||
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()), | ||
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()), | ||
sdk.NewAttribute(types.AttributeKeyDstPort, packet.GetDestPort()), | ||
sdk.NewAttribute(types.AttributeKeyDstChannel, packet.GetDestChannel()), | ||
sdk.NewAttribute(types.AttributeKeyChannelOrdering, channel.Ordering.String()), | ||
// we only support 1-hop packets now, and that is the most important hop for a relayer | ||
// (is it going to a chain I am connected to) | ||
sdk.NewAttribute(types.AttributeKeyConnection, channel.ConnectionHops[0]), | ||
), | ||
sdk.NewEvent( | ||
sdk.EventTypeMessage, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), | ||
), | ||
}) | ||
} | ||
|
||
// EmitWriteAcknowledgementEvent emits an event that the relayer can query for | ||
func EmitWriteAcknowledgementEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel, acknowledgement []byte) { | ||
ctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
types.EventTypeWriteAck, | ||
sdk.NewAttribute(types.AttributeKeyData, string(packet.GetData())), // DEPRECATED | ||
sdk.NewAttribute(types.AttributeKeyDataHex, hex.EncodeToString(packet.GetData())), | ||
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, packet.GetTimeoutHeight().String()), | ||
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())), | ||
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())), | ||
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()), | ||
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()), | ||
sdk.NewAttribute(types.AttributeKeyDstPort, packet.GetDestPort()), | ||
sdk.NewAttribute(types.AttributeKeyDstChannel, packet.GetDestChannel()), | ||
sdk.NewAttribute(types.AttributeKeyAck, string(acknowledgement)), | ||
sdk.NewAttribute(types.AttributeKeyAckHex, hex.EncodeToString(acknowledgement)), | ||
// we only support 1-hop packets now, and that is the most important hop for a relayer | ||
// (is it going to a chain I am connected to) | ||
sdk.NewAttribute(types.AttributeKeyConnection, channel.ConnectionHops[0]), | ||
), | ||
sdk.NewEvent( | ||
sdk.EventTypeMessage, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), | ||
), | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
e
invent
.And also there's no reason to make the
p
ofPacket
uppercase.