-
Notifications
You must be signed in to change notification settings - Fork 751
feat(transfer): use registered error code for error acks in token forwarding #6648
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
Changes from 5 commits
aec52a4
2d1575b
a35cb6d
69155ad
5965c83
aeb5162
ab3149a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,6 +174,19 @@ func ParseProposalIDFromEvents(events []abci.Event) (uint64, error) { | |
| return 0, fmt.Errorf("proposalID event attribute not found") | ||
| } | ||
|
|
||
| // ParsePacketSequenceFromEvents parses events emitted from MsgRecvPacket and returns the packet sequence | ||
| func ParsePacketSequenceFromEvents(events []abci.Event) (uint64, error) { | ||
| for _, event := range events { | ||
| for _, attribute := range event.Attributes { | ||
| if attribute.Key == "packet_sequence" { | ||
| return strconv.ParseUint(attribute.Value, 10, 64) | ||
| } | ||
|
Comment on lines
+180
to
+183
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] Depending on how much you (dis)like nested loops, you could also go with something like: for _, event := range events {
if idx := slices.IndexFunc(event.Attributes,func(a abci.EventAttribute) bool {return a.Key == "packet_sequence"}); idx != -1 {
return strconv.ParseUint(event.Attributes[idx].Value, 10, 64)
}
}
return 0, fmt.Errorf("packet sequence event attribute not found")
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. To be honest I copied the function above which is very similar, but I could change to this. I'm not a fan of nested loops, but I am not sure if this reads a lot better, though?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tend to prefer structures like this but this is personal preference. If it is used more than once (I see also at least 3 more usages at the top of the file) we could extract it to an helper fn: func attributeByKey(key string, attributes []abci.EventAttribute) (Attribute, bool) {
if idx := slices.IndexFunc(event.Attributes,func(a abci.EventAttribute) bool {return a.Key == key}); idx == -1 {
return abci.Attribute{}, false
}
return attributes[idx], true
}So that we can later just do: for _, event := range events {
if attribute, found := attributeByKey("packet_sequence", event.Attributes); found {
return strconv.ParseUint(attribute.Value, 10, 64)
}
}Which I think makes things easier to read.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That does make sense! I'll look into that :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be interested in a generic fn for parsing event attributes so we don't need to add a helper fn for each attribute, but maybe lets take this discussion to a separate issue?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| } | ||
|
|
||
| return 0, fmt.Errorf("packet sequence event attribute not found") | ||
| } | ||
|
|
||
| // AssertEvents asserts that expected events are present in the actual events. | ||
| func AssertEvents( | ||
| suite *testifysuite.Suite, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes on this file seem to mix the purpose of the PR (use registered error code) with some other refactoring. WDYT about moving them into a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does to some extent, but a good chunk of the refactor was to make use of the added error code in a test. Some of it I could've potentially skipped, but it would only be a relatively small portion. I did expect the refactor to be slightly smaller, though. If there are concerns about the refactor itself, I could take it out and not test that error message. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine by me to let it like this. But since my understanding of the test code is still fuzzy, I'll just refrain from LGTMing it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, less diffs are always appreciated. But this felt like an okay amount.