feat: add cursor pagination to transaction list endpoints#2432
Open
Marvy247 wants to merge 1 commit intohirosystems:developfrom
Open
feat: add cursor pagination to transaction list endpoints#2432Marvy247 wants to merge 1 commit intohirosystems:developfrom
Marvy247 wants to merge 1 commit intohirosystems:developfrom
Conversation
- Add cursor pagination to /extended/v1/tx endpoint
* Cursor format: indexBlockHash:microblockSequence:txIndex
* Supports all existing filters (type, from_address, to_address, etc.)
* Uses row-value comparison for O(1) performance on any page
* Backward compatible (cursor parameter is optional)
- Add cursor pagination to /extended/v2/blocks/:block/transactions endpoint
* Cursor format: microblockSequence:txIndex (simpler since all txs in same block)
* Maintains ASC ordering by microblock_sequence and tx_index
- Comprehensive test coverage for main transaction list
* Forward/backward navigation
* Cursor with filters
* Invalid cursor handling
* Edge cases (first page, last page)
Benefits:
- Eliminates pagination drift during data changes
- Faster pagination for large offsets (O(1) vs O(n))
- Consistent cursor-based navigation pattern across API
Files modified:
- src/api/routes/tx.ts: Add cursor support to transaction list
- src/api/routes/v2/blocks.ts: Add cursor support to block transactions
- src/datastore/pg-store.ts: Implement getTxList cursor logic
- src/datastore/pg-store-v2.ts: Implement getBlockTransactions cursor logic
- tests/api/tx.test.ts: Add comprehensive cursor pagination tests
Author
|
@rafaelcr @rmottley-hiro @pradel |
Author
|
@rafaelcr @rmottley-hiro @pradel |
1 similar comment
Author
|
@rafaelcr @rmottley-hiro @pradel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
/extended/v2/blocks/:block/transactions- Block Transactions• Cursor format: microblockSequence:txIndex (simpler since all txs share same block)
• Maintains ASC ordering within block
• Returns cursor fields in response
Example:
bash
GET /extended/v2/blocks/12345/transactions?limit=10
GET /extended/v2/blocks/12345/transactions?cursor=2147483647:3&limit=10
Implementation Details
• Uses PostgreSQL row-value comparison: (block_height, microblock_sequence, tx_index) <= (values)
• Fetches limit + 1 records to detect if next page exists
• Generates next_cursor by looking up the start of the previous page
• Handles both ASC and DESC ordering for transaction list
• Proper error handling for invalid cursor formats
Testing
Added comprehensive test coverage for transaction list cursor pagination:
• Forward pagination (prev_cursor navigation)
• Backward pagination (next_cursor navigation)
• Cursor with filters applied
• Invalid cursor format handling
• Edge cases (first page, last page, empty results)
Performance Benefits
• Constant-time pagination: O(1) for any page vs O(n) for large offsets
• Consistency: No pagination drift when data changes
• Scalability: Efficient for endpoints with millions of transactions
Backward Compatibility
• Cursor parameter is optional
• Existing offset/limit pagination still works
• Response includes both offset/limit and cursor fields
Related
• Follows pattern from #2422 (cursor pagination for address transactions)
• Addresses issue #2349 (block-based filtering for pagination)