Skip to content
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

Merged
merged 7 commits into from
May 22, 2023
Merged

accounts/abi: add ErrorById #27277

merged 7 commits into from
May 22, 2023

Conversation

chawin-a
Copy link
Contributor

Changes

  • Modify ID type from common.Hash to []byte in Error struct
  • Add ErrorById

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]) {
Copy link
Contributor

@fjl fjl May 16, 2023

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 sigdata parameter to [4]byte
  • do the check like bytes.Equal(errABI.ID[:4], sigdata[:])

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@deep709
Copy link

deep709 commented May 16, 2023

Thanks all

@chawin-a chawin-a requested a review from fjl May 17, 2023 06:44
@fjl
Copy link
Contributor

fjl commented May 17, 2023

Please apply the requested changes!

@chawin-a
Copy link
Contributor Author

Done please review the changes

Copy link
Contributor

@fjl fjl left a 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

@@ -38,7 +37,7 @@ type Error struct {

// 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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor Author

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.

@@ -222,6 +222,17 @@ func (abi *ABI) EventByID(topic common.Hash) (*Event, error) {
return nil, fmt.Errorf("no event with id: %#x", topic.Hex())
}

// ErrorById looks up an error by the 4-byte id,
// returns nil if none found.
func (abi *ABI) ErrorById(sigdata [4]byte) (*Error, error) {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@chawin-a
Copy link
Contributor Author

Please review the changes again.

@chawin-a chawin-a requested a review from fjl May 18, 2023 04:26
}
for name, m := range abi.Errors {
a := fmt.Sprintf("%v", &m)
id := *(*[4]byte)(m.ID[:4])
Copy link
Member

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Thanks for review

Copy link
Member

@MariusVanDerWijden MariusVanDerWijden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@holiman holiman added this to the 1.11.7 milestone May 22, 2023
Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@holiman holiman merged commit 5b792e0 into ethereum:master May 22, 2023
devopsbo3 pushed a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants