-
Notifications
You must be signed in to change notification settings - Fork 121
feat: add cursor pagination to sc events #2351
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
base: develop
Are you sure you want to change the base?
Conversation
|
Vercel deployment URL: https://stacks-blockchain-1xeisooxq-hirosystems.vercel.app 🚀 |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
@ASuciuX thanks for giving a shot at this pr. With this cursor based approach, will it be possible to got from event 1 (the first one that happened) to the last one? My use case would be to index all the events from the start to a specific block. |
|
Yes, with the cursor you can iterate forward from the very first event to the latest, page by page. It’s designed so you can start at genesis and stop at any specific block height. |
|
Amazing, looking forward to be able to use this approach 🙏 |
| // Validate cursor format if provided | ||
| if (cursor && !cursor.match(/^\d+-\d+-\d+$/)) { | ||
| throw new InvalidRequestError( | ||
| 'Invalid cursor format. Expected format: blockHeight-txIndex-eventIndex', |
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.
Instead of a block height, the cursor should use the index block hash so it is resistent to re-orgs. If you look at Matt's approach to cursors in the other endpoints, he uses this approach and also tests with different re-org scenarios.
This will change your queries a bit but you'll just need to transform from the index block hash into the block height before using your current filters.
[wip] to add prev_cursor
Fixes #2349 by adding cursor-based pagination for events. This provides stable iteration through results, unlike offset-based pagination where responses can shift as new events are added.