Skip to content

Commit d14f550

Browse files
chandiniv1DimitrisJimdamiannolan
authored
use generic helper function for parsing event attributes (#6836)
* create generic helper function for parsing event attributes * review: Align sig with other attr helpers (attrs, key) Slap docusting Amend contains to re-use it. Use in ParseAckFromEvents * update helper --------- Co-authored-by: DimitrisJim <[email protected]> Co-authored-by: Damian Nolan <[email protected]>
1 parent 1767816 commit d14f550

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

testing/events.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ import (
2020
func ParseClientIDFromEvents(events []abci.Event) (string, error) {
2121
for _, ev := range events {
2222
if ev.Type == clienttypes.EventTypeCreateClient {
23-
for _, attr := range ev.Attributes {
24-
if attr.Key == clienttypes.AttributeKeyClientID {
25-
return attr.Value, nil
26-
}
23+
if attribute, found := attributeByKey(ev.Attributes, clienttypes.AttributeKeyClientID); found {
24+
return attribute.Value, nil
2725
}
2826
}
2927
}
@@ -36,10 +34,8 @@ func ParseConnectionIDFromEvents(events []abci.Event) (string, error) {
3634
for _, ev := range events {
3735
if ev.Type == connectiontypes.EventTypeConnectionOpenInit ||
3836
ev.Type == connectiontypes.EventTypeConnectionOpenTry {
39-
for _, attr := range ev.Attributes {
40-
if attr.Key == connectiontypes.AttributeKeyConnectionID {
41-
return attr.Value, nil
42-
}
37+
if attribute, found := attributeByKey(ev.Attributes, connectiontypes.AttributeKeyConnectionID); found {
38+
return attribute.Value, nil
4339
}
4440
}
4541
}
@@ -51,10 +47,8 @@ func ParseConnectionIDFromEvents(events []abci.Event) (string, error) {
5147
func ParseChannelIDFromEvents(events []abci.Event) (string, error) {
5248
for _, ev := range events {
5349
if ev.Type == channeltypes.EventTypeChannelOpenInit || ev.Type == channeltypes.EventTypeChannelOpenTry {
54-
for _, attr := range ev.Attributes {
55-
if attr.Key == channeltypes.AttributeKeyChannelID {
56-
return attr.Value, nil
57-
}
50+
if attribute, found := attributeByKey(ev.Attributes, channeltypes.AttributeKeyChannelID); found {
51+
return attribute.Value, nil
5852
}
5953
}
6054
}
@@ -162,7 +156,6 @@ func ParseAckFromEvents(events []abci.Event) ([]byte, error) {
162156
if err != nil {
163157
return nil, err
164158
}
165-
166159
return value, nil
167160
}
168161
}

0 commit comments

Comments
 (0)