-
Notifications
You must be signed in to change notification settings - Fork 182
/
events.go
30 lines (25 loc) · 987 Bytes
/
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
package keeper
import (
"fmt"
sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
icatypes "github.com/okex/exchain/libs/ibc-go/modules/apps/27-interchain-accounts/types"
"github.com/okex/exchain/libs/ibc-go/modules/core/exported"
)
// EmitAcknowledgementEvent emits an event signalling a successful or failed acknowledgement and including the error
// details if any.
func EmitAcknowledgementEvent(ctx sdk.Context, packet exported.PacketI, ack exported.Acknowledgement, err error) {
attributes := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName),
sdk.NewAttribute(icatypes.AttributeKeyControllerChannelID, packet.GetDestChannel()),
sdk.NewAttribute(icatypes.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success())),
}
if err != nil {
attributes = append(attributes, sdk.NewAttribute(icatypes.AttributeKeyAckError, err.Error()))
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(
icatypes.EventTypePacket,
attributes...,
),
)
}