Skip to content

Commit

Permalink
chore: add events for write ack.
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim committed Nov 21, 2024
1 parent 5e427c0 commit 0839208
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
23 changes: 20 additions & 3 deletions modules/core/04-channel/v2/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,26 @@ func EmitTimeoutPacketEvents(ctx context.Context, packet types.Packet) {
// TODO: https://github.com/cosmos/ibc-go/issues/7386
}

// EmitWriteAcknowledgementEvents emits events for WriteAcknowledgement.
func EmitWriteAcknowledgementEvents(ctx context.Context, packet types.Packet, ack types.Acknowledgement) {
// TODO: https://github.com/cosmos/ibc-go/issues/7386
// emitWriteAcknowledgementEvents emits events for WriteAcknowledgement.
func emitWriteAcknowledgementEvents(ctx context.Context, packet types.Packet, ack types.Acknowledgement) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

for i, ack := range ack.AppAcknowledgements {
sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeWriteAcknowledgement,
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.SourceChannel),
sdk.NewAttribute(types.AttributeKeyDstChannel, packet.DestinationChannel),
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.Sequence)),
sdk.NewAttribute(types.AttributeKeyPayloadSequence, fmt.Sprintf("%d", i)),
sdk.NewAttribute(types.AttributeKeyAcknowledgement, hex.EncodeToString(ack)),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
),
})
}
}

// emitCreateChannelEvent emits a channel create event.
Expand Down
3 changes: 1 addition & 2 deletions modules/core/04-channel/v2/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ func (k Keeper) WriteAcknowledgement(

k.Logger(ctx).Info("acknowledgement written", "sequence", strconv.FormatUint(packet.Sequence, 10), "dest-channel", packet.DestinationChannel)

// TODO: decide how relayers will reconstruct the packet as it is not being passed.
// EmitWriteAcknowledgementEvents(ctx, packet, ack)
emitWriteAcknowledgementEvents(ctx, packet, ack)

// TODO: delete the packet that has been stored in ibc-core.

Expand Down
5 changes: 4 additions & 1 deletion modules/core/04-channel/v2/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const (
EventTypeCreateChannel = "create_channel"
EventTypeRegisterCounterparty = "register_counterparty"
EventTypeSendPacket = "send_packet"
EventTypeSendPayload = "send_payload"
EventTypeWriteAcknowledgement = "write_acknowledgement"

EventTypeSendPayload = "send_payload"

AttributeKeyChannelID = "channel_id"
AttributeKeyClientID = "client_id"
Expand All @@ -25,6 +27,7 @@ const (
AttributeKeyVersion = "payload_version"
AttributeKeyEncoding = "payload_encoding"
AttributeKeyData = "payload_data"
AttributeKeyAcknowledgement = "acknowledgement"
)

// IBC channel events vars
Expand Down

0 comments on commit 0839208

Please sign in to comment.