feat: add cursor pagination to transaction list endpoints #2432
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)