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

feat: implement eth_getLogs #830

Merged
merged 5 commits into from
Sep 20, 2023

Conversation

zhangliugang
Copy link
Contributor

Summary of Changes

implement eth.getLogs to query events from evm,
Consult:
https://github.com/ethers-io/ethers.js/blob/32915634bef5b81c6d9998f4e9ad812ffe721954/src.ts/abi/interface.ts#L1007

fix: EventFilterParameters.encode(), Topic can not encode as a single string

Test Data or Screenshots

By submitting this pull request, you are confirming the following:
  • I have reviewed the Contribution Guidelines.
  • I have performed a self-review of my own code.
  • I have updated my repository to match the develop branch.
  • I have included test data or screenshots that prove my fix is effective or that my feature works.
  • I have checked that all tests work and swiftlint is not throwing any errors/warnings.

@zhangliugang zhangliugang changed the title feat: enable encode Event and IETH.getLogs feat: implement eth_getLogs Aug 24, 2023
Tests/web3swiftTests/localTests/EventTests.swift Outdated Show resolved Hide resolved
Tests/web3swiftTests/remoteTests/EventFilterTests.swift Outdated Show resolved Hide resolved
Tests/web3swiftTests/localTests/EventTests.swift Outdated Show resolved Hide resolved
Comment on lines 264 to 266
} else if input.type.isArray {
// filtering with tuples or arrays not supported
return []
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: move it up and potentially combine into a guard statement with input.indexed.

guard input.indexed, !input.type.isArray else { return [] }

This comment was marked as resolved.

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 figured it out. If we have a event with 3 fields like

event TestEvent(string indexed f1, int[] indexed f2, int32 indexed f3);

When we want to build a filter to query this event with first and third fields, we have to pass nil to second field, and the topicFilter will be like

[
  '0x07c9b1ca6e62a19a2af4d11a151945afc7d47c89c716a74973b49572c1a715f4',
  '0xab036729af8b8f9b610af4e11b14fa30c348f40c2c230cce92ef6ef37726fee7',
  null,
  '0x0000000000000000000000000000000000000000000000000000000000000064'
]

If combine input.indexed and input.type.isArray together, we can only build a filter with first one field.

Copy link
Collaborator

@JeneaVranceanu JeneaVranceanu left a comment

Choose a reason for hiding this comment

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

lgtm!

@JeneaVranceanu JeneaVranceanu merged commit 2d4bffd into web3swift-team:develop Sep 20, 2023
2 checks passed
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.

2 participants