Skip to content

Commit

Permalink
chore: add event for register counterparty (#7556)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim authored Nov 12, 2024
1 parent d416dc3 commit 6b237fc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
18 changes: 18 additions & 0 deletions modules/core/04-channel/v2/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,21 @@ func (*Keeper) emitCreateChannelEvent(ctx context.Context, channelID, clientID s
),
})
}

// emitRegisterCounterpartyEvent emits a register counterparty event.
func (*Keeper) emitRegisterCounterpartyEvent(ctx context.Context, channelID string, channel types.Channel) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeRegisterCounterparty,
sdk.NewAttribute(types.AttributeKeyChannelID, channelID),
sdk.NewAttribute(types.AttributeKeyClientID, channel.ClientId),
sdk.NewAttribute(types.AttributeKeyCounterpartyChannelID, channel.CounterpartyChannelId),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
),
})
}
2 changes: 2 additions & 0 deletions modules/core/04-channel/v2/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func (k *Keeper) RegisterCounterparty(goCtx context.Context, msg *types.MsgRegis
// Delete client creator from state as it is not needed after this point.
k.DeleteCreator(ctx, msg.ChannelId)

k.emitRegisterCounterpartyEvent(goCtx, msg.ChannelId, channel)

return &types.MsgRegisterCounterpartyResponse{}, nil
}

Expand Down
8 changes: 5 additions & 3 deletions modules/core/04-channel/v2/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (

// IBC channel events
const (
AttributeKeyChannelID = "channel_id"
AttributeKeyClientID = "client_id"
AttributeKeyChannelID = "channel_id"
AttributeKeyClientID = "client_id"
AttributeKeyCounterpartyChannelID = "counterparty_channel_id"
)

// IBC channel events vars
var (
EventTypeCreateChannel = "create_channel"
EventTypeCreateChannel = "create_channel"
EventTypeRegisterCounterparty = "register_counterparty"

AttributeValueCategory = fmt.Sprintf("%s_%s", ibcexported.ModuleName, SubModuleName)
)

0 comments on commit 6b237fc

Please sign in to comment.