-
Notifications
You must be signed in to change notification settings - Fork 9
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
💡 [REQUEST] - Add fragment support for filterEventLogs
#774
Comments
Hi @ifavo, even in this case, you can access the filter from the contract object and the topics will be encoded: const contract = thorSoloClient.contracts.load(
CONTRACT_ADDRESS,
CONTRACT_ABI
);
await contract.filters .Transfer(FROM_ADDRESS).get() // pass the criterias as arguments |
@Valazan that's great to know! thank you 🙏 With the function With your example I can query for a single event but can not filter for multiples in the same request, like I am able to do on the node-API. |
@ifavo yes, currently multiple events are not supported. I'll create an issue to implement your suggested call to enable the direct use of fragments with encoded args and the filtering of multiple events. |
@ifavo I'm adding to the planning also the possibility to build a criteria from a contract object. So this call await thor.logs.filterEventLogs(
criteriaSet: [
{
address: '0x0000000000000000000000000000456e65726779',
fragment: 'event Transfer(address indexed from, address indexed to, uint256 amount)',
args: ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac']
}
]
}) Could also be invoked like this: await thor.logs.filterEventLogs(
criteriaSet: [
contract.criteria.Transfer('0xd8da6bf26964af9d7eed9e03e53415d37aa96045', '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac')
]
}) |
Modify the current thor.logs.filterEventLogs to support the feature Events will be filtered in both these ways, by either using a fragment or the contract object: await thor.logs.filterEventLogs(
criteriaSet: [
{
address: '0x0000000000000000000000000000456e65726779',
fragment: 'event Transfer(address indexed from, address indexed to, uint256 amount)',
args: ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac']
}
]
}) Could also be invoked like this: await thor.logs.filterEventLogs(
criteriaSet: [
contract.criteria.Transfer('0xd8da6bf26964af9d7eed9e03e53415d37aa96045', '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac')
]
}) |
@Valazan @nwbrettski May I suggest to also decode the data before returning it? The same is already happening on calling contract functions, the returned data is decoded. Asking the user to manually decode them for events adds, in my opinion, an unnecessary burden. I can separate this into a new issue if you like. |
@Valazan thank you for making the improvement 🙌 I have a question regarding compatibility. SyntaxAs far as I understand you changed it from: const filteredLogs = await thor.logs.filterEventLogs({
criteriaSet: EventCriteria[]
}) to: const filteredLogs = await thor.logs.filterEventLogs({
criteriaSet: {
criteria: EventCriteria
eventFragment: EventFragment
}[]
}) Why not keep it compatible with previous code by accepting both versions? const filteredLogs = await thor.logs.filterEventLogs({
criteriaSet: (EventCriteria | EventFragment)[]
}) Topic Hash now requiredFiltering just by address, without hash worked before and is also supported by the node, it fails now with
Is this a wanted change? |
Summary
logs.filterEventLogs
requires manually encoding the log filter, which is handled within other parts of the SDK already by supporting fragments.The example code right now is:
Basic Example
Support fragments, the sample snippet above could be reduced to:
Its basically what already happens within
getEventSubscriptionUrl
:vechain-sdk-js/packages/network/src/utils/subscriptions/event.ts
Lines 28 to 46 in 0b214f1
The text was updated successfully, but these errors were encountered: