-
Notifications
You must be signed in to change notification settings - Fork 21.6k
accounts/abi: add ErrorById #27277
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
accounts/abi: add ErrorById #27277
Conversation
accounts/abi/abi.go
Outdated
| return nil, fmt.Errorf("data too short (%d bytes) for abi error lookup", len(sigdata)) | ||
| } | ||
| for _, errABI := range abi.Errors { | ||
| if bytes.Equal(errABI.ID, sigdata[:4]) { |
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.
I wonder why you changed the ID field to []byte. Might be better to:
- change the type of the
sigdataparameter to[4]byte - do the check like
bytes.Equal(errABI.ID[:4], sigdata[:])
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.
I implement it in the same way as MethodById did. I'll modify it if [4]byte is better.
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 my opinion, []byte is better because I can use ErrorData as an input to find abi.Error.
|
Thanks all |
|
Please apply the requested changes! |
|
Done please review the changes |
fjl
left a comment
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.
Sorry some more changes needed
accounts/abi/error.go
Outdated
| // ID returns the canonical representation of the error's signature used by the | ||
| // abi definition to identify event names and types. | ||
| ID common.Hash | ||
| ID [4]byte |
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.
You don't need to change the ID to make the function ErrorByID work.
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.
Fixed
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.
I changed ID back to common.Hash.
accounts/abi/abi.go
Outdated
|
|
||
| // ErrorById looks up an error by the 4-byte id, | ||
| // returns nil if none found. | ||
| func (abi *ABI) ErrorById(sigdata [4]byte) (*Error, error) { |
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.
Please rename this method to ErrorByID
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.
Done
|
Please review the changes again. |
accounts/abi/abi_test.go
Outdated
| } | ||
| for name, m := range abi.Errors { | ||
| a := fmt.Sprintf("%v", &m) | ||
| id := *(*[4]byte)(m.ID[:4]) |
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.
I think you should do something like this:
var id [4]byte
copy(id[:], m.ID[:4])
Thanks for submitting this!
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.
Done! Thanks for review
MariusVanDerWijden
left a comment
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.
LGTM
holiman
left a comment
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.
LGTM
Adds `ErrorById` lookup
This reverts commit c6b8a40.
This reverts commit c6b8a40.
Adds `ErrorById` lookup
Changes
common.Hashto[]bytein Error struct