accounts/abi: add ErrorById#27277
Conversation
| 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.
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.
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.
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.
Sorry some more changes needed
| // 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.
You don't need to change the ID to make the function ErrorByID work.
There was a problem hiding this comment.
I changed ID back to common.Hash.
|
|
||
| // 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.
Please rename this method to ErrorByID
|
Please review the changes again. |
| } | ||
| for name, m := range abi.Errors { | ||
| a := fmt.Sprintf("%v", &m) | ||
| id := *(*[4]byte)(m.ID[:4]) |
There was a problem hiding this comment.
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.
Done! Thanks for review
Adds `ErrorById` lookup
This reverts commit c6b8a40.
This reverts commit c6b8a40.
Adds `ErrorById` lookup
Changes
common.Hashto[]bytein Error struct