Skip to content
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

Fix: ibc transfer parsing inside eth tx #889

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 44 additions & 37 deletions usecase/parser/ibc/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,50 +927,57 @@ func ParseMsgTransfer(
}

log := utils.NewParsedTxsResultLog(&parserParams.TxsResult.Log[parserParams.MsgIndex])
event := log.GetEventByType("send_packet")
if event == nil {
panic("missing `send_packet` event in TxsResult log")
}

if parserParams.IsEthereumTxInnerMsg {
// Transfer application, MsgTransfer
packetData := event.MustGetAttributeByKey("packet_data")
var fungiblePacketData ibc_model.FungibleTokenPacketData
events := log.GetEventsByType("send_packet")
for _, event := range events {
// Transfer application, MsgTransfer
packetData := event.MustGetAttributeByKey("packet_data")

if unmarshalErr := jsoniter.Unmarshal([]byte(packetData), &fungiblePacketData); unmarshalErr != nil {
panic("unable to parse `send_packet` event, key `packet_data`")
}
var fungiblePacketData *ibc_model.FungibleTokenPacketData
if unmarshalErr := jsoniter.Unmarshal([]byte(packetData), &fungiblePacketData); unmarshalErr != nil {
panic("unable to parse `send_packet` event, key `packet_data`")
}

msgTransferParams := ibc_model.MsgTransferParams{
RawMsgTransfer: ibc_model.RawMsgTransfer{
Token: ibc_model.MsgTransferToken{
Denom: fungiblePacketData.Denom,
Amount: fungiblePacketData.Amount,
},
Sender: fungiblePacketData.Sender,
Receiver: fungiblePacketData.Receiver,
SourcePort: event.MustGetAttributeByKey("packet_src_port"),
SourceChannel: event.MustGetAttributeByKey("packet_src_channel"),
TimeoutHeight: MustParseHeight(event.MustGetAttributeByKey("packet_timeout_height")),
TimeoutTimestamp: event.MustGetAttributeByKey("packet_timeout_timestamp"),
},
if fungiblePacketData != nil {
msgTransferParams := ibc_model.MsgTransferParams{
RawMsgTransfer: ibc_model.RawMsgTransfer{
Token: ibc_model.MsgTransferToken{
Denom: fungiblePacketData.Denom,
Amount: fungiblePacketData.Amount,
},
Sender: fungiblePacketData.Sender,
Receiver: fungiblePacketData.Receiver,
SourcePort: event.MustGetAttributeByKey("packet_src_port"),
SourceChannel: event.MustGetAttributeByKey("packet_src_channel"),
TimeoutHeight: MustParseHeight(event.MustGetAttributeByKey("packet_timeout_height")),
TimeoutTimestamp: event.MustGetAttributeByKey("packet_timeout_timestamp"),
},

PacketSequence: typeconv.MustAtou64(event.MustGetAttributeByKey("packet_sequence")),
DestinationPort: event.MustGetAttributeByKey("packet_dst_port"),
DestinationChannel: event.MustGetAttributeByKey("packet_dst_channel"),
ChannelOrdering: event.MustGetAttributeByKey("packet_channel_ordering"),
ConnectionID: event.MustGetAttributeByKey("packet_connection"),
PacketData: fungiblePacketData,
}
// Getting possible signer address from Msg
var possibleSignerAddresses []string
possibleSignerAddresses = append(possibleSignerAddresses, msgTransferParams.Sender)
PacketSequence: typeconv.MustAtou64(event.MustGetAttributeByKey("packet_sequence")),
DestinationPort: event.MustGetAttributeByKey("packet_dst_port"),
DestinationChannel: event.MustGetAttributeByKey("packet_dst_channel"),
ChannelOrdering: event.MustGetAttributeByKey("packet_channel_ordering"),
ConnectionID: event.MustGetAttributeByKey("packet_connection"),
PacketData: *fungiblePacketData,
}

return []command.Command{command_usecase.NewCreateMsgIBCTransferTransfer(
parserParams.MsgCommonParams,
// Getting possible signer address from Msg
var possibleSignerAddresses []string
possibleSignerAddresses = append(possibleSignerAddresses, msgTransferParams.Sender)

msgTransferParams,
)}, possibleSignerAddresses
return []command.Command{command_usecase.NewCreateMsgIBCTransferTransfer(
parserParams.MsgCommonParams,

msgTransferParams,
)}, possibleSignerAddresses
}
}
}

event := log.GetEventByType("send_packet")
if event == nil {
panic("missing `send_packet` event in TxsResult log")
}

packetData := event.MustGetAttributeByKey("packet_data")
Expand Down
3 changes: 2 additions & 1 deletion usecase/parser/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2505,7 +2505,8 @@ func ParseMsgEthereumTx(
// parse msgTransfer
case log.HasEvent("send_packet"):
{
if log.GetEventByType("send_packet") != nil {
sendEvents := log.GetEventsByType("send_packet")
if len(sendEvents) > 0 {
parserParams.IsEthereumTxInnerMsg = true
cmds, signers := ibc.ParseMsgTransfer(parserParams)
commands = append(commands, cmds...)
Expand Down
Loading