diff --git a/x/common/types/events.go b/x/common/types/events.go index 4d19492de..8e383a998 100644 --- a/x/common/types/events.go +++ b/x/common/types/events.go @@ -1,7 +1,7 @@ package types +// RollappPacket attributes const ( - // RollappPacket events AttributeKeyRollappId = "rollapp_id" AttributeKeyPacketStatus = "status" AttributeKeyPacketSourcePort = "source_port" @@ -9,5 +9,17 @@ const ( AttributeKeyPacketDestinationPort = "destination_port" AttributeKeyPacketDestinationChannel = "destination_channel" AttributeKeyPacketSequence = "packet_sequence" + AttributeKeyPacketProofHeight = "proof_height" + AttributeKeyPacketType = "type" + AttributeKeyPacketAcknowledgement = "acknowledgement" AttributeKeyPacketError = "error" ) + +// FungibleTokenPacketData attributes +const ( + AttributeKeyPacketDataDenom = "packet_data_denom" + AttributeKeyPacketDataAmount = "packet_data_amount" + AttributeKeyPacketDataSender = "packet_data_sender" + AttributeKeyPacketDataReceiver = "packet_data_receiver" + AttributeKeyPacketDataMemo = "packet_data_memo" +) diff --git a/x/common/types/rollapp_packet.go b/x/common/types/rollapp_packet.go index e1267b1b5..dbdfa94ba 100644 --- a/x/common/types/rollapp_packet.go +++ b/x/common/types/rollapp_packet.go @@ -6,6 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ) func (r RollappPacket) LogString() string { @@ -38,6 +39,26 @@ func (r RollappPacket) ValidateBasic() error { } func (r RollappPacket) GetEvents() []sdk.Attribute { + var pd transfertypes.FungibleTokenPacketData + if len(r.Packet.Data) != 0 { + // It's okay if we can't get packet data + pd, _ = r.GetTransferPacketData() + } + + acknowledgement := "none" + if len(r.Acknowledgement) != 0 { + ack, err := r.GetAck() + // It's okay if we can't get acknowledgement + if err == nil { + switch ack.GetResponse().(type) { + case *channeltypes.Acknowledgement_Result: + acknowledgement = "success" + case *channeltypes.Acknowledgement_Error: + acknowledgement = "error" + } + } + } + eventAttributes := []sdk.Attribute{ sdk.NewAttribute(AttributeKeyRollappId, r.RollappId), sdk.NewAttribute(AttributeKeyPacketStatus, r.Status.String()), @@ -46,6 +67,14 @@ func (r RollappPacket) GetEvents() []sdk.Attribute { sdk.NewAttribute(AttributeKeyPacketDestinationPort, r.Packet.DestinationPort), sdk.NewAttribute(AttributeKeyPacketDestinationChannel, r.Packet.DestinationChannel), sdk.NewAttribute(AttributeKeyPacketSequence, strconv.FormatUint(r.Packet.Sequence, 10)), + sdk.NewAttribute(AttributeKeyPacketProofHeight, strconv.FormatUint(r.ProofHeight, 10)), + sdk.NewAttribute(AttributeKeyPacketType, r.Type.String()), + sdk.NewAttribute(AttributeKeyPacketAcknowledgement, acknowledgement), + sdk.NewAttribute(AttributeKeyPacketDataDenom, pd.Denom), + sdk.NewAttribute(AttributeKeyPacketDataAmount, pd.Amount), + sdk.NewAttribute(AttributeKeyPacketDataSender, pd.Sender), + sdk.NewAttribute(AttributeKeyPacketDataReceiver, pd.Receiver), + sdk.NewAttribute(AttributeKeyPacketDataMemo, pd.Memo), } if r.Error != "" { eventAttributes = append(eventAttributes, sdk.NewAttribute(AttributeKeyPacketError, r.Error)) @@ -62,6 +91,14 @@ func (r RollappPacket) GetTransferPacketData() (transfertypes.FungibleTokenPacke return data, nil } +func (r RollappPacket) GetAck() (channeltypes.Acknowledgement, error) { + var ack channeltypes.Acknowledgement + if err := transfertypes.ModuleCdc.UnmarshalJSON(r.Acknowledgement, &ack); err != nil { + return channeltypes.Acknowledgement{}, err + } + return ack, nil +} + func (r RollappPacket) RestoreOriginalTransferTarget() (RollappPacket, error) { transferPacketData, err := r.GetTransferPacketData() if err != nil {