-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Event filtering using non/indexed string arguments #6167
Conversation
…IndexedEventWithStringIndexed function to Basic.sol
…r filter using string values
) | ||
: decodedLogs; | ||
|
||
if (filterKeys.length > 0) { |
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.
On line 729:
const logs = await getLogs(this, { fromBlock, toBlock, topics, address }, returnFormat);
we submit an RPC request to get a list of events for a period of blocks that match topics
i.e. the event signatures we're interested in. If topics === undefined
then the RPC response will contain all the events that occurred during the block period. Previously this check was:
eventName === 'allEvents' && filterKeys.length > 0
to account for this scenario as we needed to perform the filtering on the all the events returned by the RPC response using the filter
provided by the user. Usually in this scenario, the user is intending to get all the events within a block period with a specific event argument i.e. "I want all events during the block period where from
event arugment was 0x0...
". Otherwise, we skip the additional filtering because the events have already been filtered using the user's filter
by the RPC client. However, this did not work when the user's filter
was attempting to filter using a non-indexed string event argument as done in this test. By removing the check eventName === 'allEvents'
for this line, we now perform this additional filtering on all events as long as some filter
object was provided by the user. This adds support for filtering events using non-indexed and indexed string event arguments (i.e. the issue reported by #5807)
Deploying with
|
Latest commit: |
2552a2a
|
Status: | ✅ Deploy successful! |
Preview URL: | https://655f6dda.web3-js-docs.pages.dev |
Branch Preview URL: | https://wyatt-4-x-5807-contract-even.web3-js-docs.pages.dev |
Bundle StatsHey there, this message comes from a github action that helps you and reviewers to understand how these changes affect the size of this project's bundle. As this PR is updated, I'll keep you updated on how the bundle size is impacted. Total
View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger No assets were bigger Smaller No assets were smaller Unchanged
|
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## 4.x #6167 +/- ##
==========================================
+ Coverage 87.37% 87.46% +0.09%
==========================================
Files 197 197
Lines 7548 7557 +9
Branches 2059 2060 +1
==========================================
+ Hits 6595 6610 +15
+ Misses 953 947 -6
Flags with carried forward coverage won't be shown. Click here to find out more.
|
const inputAbi = abi.inputs?.filter(input => input.name === key)[0]; | ||
if (inputAbi?.indexed && inputAbi.type === 'string') { | ||
const hashedIndexedString = keccak256(filter[key] as string); | ||
if (hashedIndexedString === String(log.returnValues[key])) return true; | ||
} |
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.
This added logic adds support for filtering indexed string event arguments. Because all Solidity event topics (i.e. indexed event arguments) have to be 32 bytes
, anytime a string
is indexed for an event, it's value is represented by the keccak256
hash of the string value
const _decodeParameter = (inputType: string, clonedTopic: string) => | ||
inputType === 'string' ? clonedTopic : decodeParameter(inputType, clonedTopic); | ||
|
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.
When a indexed event input is of type string, we know that it's value is going to be the keccak256 hash of the original string value, so this change returns the hash instead of trying to decode 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.
Thanks @spacesailor24 ,
And can we have unit tests for the added logic so the test coverage does not decrease?
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, except some existing change requests.
This PR fixes filter contract events using non-indexed string event arguments and adds support for filtering using indexed string event arguments
closes #5807