Skip to content

Commit

Permalink
refactor: use legacy approach first, fallback onto new parsing approach
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-axner committed Aug 29, 2023
1 parent 552e893 commit 33e466e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions relayer/chains/cosmos/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,8 @@ func parseEventsFromTxResponse(resp *sdk.TxResponse) []provider.RelayerEvent {
return events
}

// After SDK v0.50, indexed events are no longer provided in the logs on
// transaction execution, the response events can be directly used
if len(resp.Events) != 0 {
for _, event := range resp.Events {
for _, logs := range resp.Logs {
for _, event := range logs.Events {
attributes := make(map[string]string)
for _, attribute := range event.Attributes {
attributes[attribute.Key] = attribute.Value
Expand All @@ -520,12 +518,12 @@ func parseEventsFromTxResponse(resp *sdk.TxResponse) []provider.RelayerEvent {
Attributes: attributes,
})
}
return events
}

// fallback on legacy behaviour
for _, logs := range resp.Logs {
for _, event := range logs.Events {
// After SDK v0.50, indexed events are no longer provided in the logs on
// transaction execution, the response events can be directly used
if len(events) == 0 {
for _, event := range resp.Events {
attributes := make(map[string]string)
for _, attribute := range event.Attributes {
attributes[attribute.Key] = attribute.Value
Expand All @@ -536,6 +534,7 @@ func parseEventsFromTxResponse(resp *sdk.TxResponse) []provider.RelayerEvent {
})
}
}

return events
}

Expand Down

0 comments on commit 33e466e

Please sign in to comment.