Add order parameter to getEvents for descending order support#576
Draft
tomerweller wants to merge 2 commits intostellar:mainfrom
Draft
Add order parameter to getEvents for descending order support#576tomerweller wants to merge 2 commits intostellar:mainfrom
order parameter to getEvents for descending order support#576tomerweller wants to merge 2 commits intostellar:mainfrom
Conversation
This adds an optional `order` field to the getEvents pagination options, allowing clients to retrieve events in descending order (newest first). Changes: - Update DB layer to accept order parameter for query direction - Update handler to use protocol.EventOrder types - Add tests for descending order, limit with descending, and invalid order This feature enables efficient querying of the N most recent events without scanning the entire retention window. The implementation is fully backwards compatible - order defaults to "asc" when not specified. Depends on: stellar/go-stellar-sdk#5888 Closes stellar#575 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
6082035 to
d377b79
Compare
For DESC order, startLedger now acts as the upper bound (where we start scanning backwards from) and endLedger acts as the lower bound. This makes DESC order intuitive for 'get N most recent events' use case: - Set startLedger to the maximum ledger you want - Results will include events up to and including startLedger - Events are returned newest first For ASC order (default), behavior is unchanged: - startLedger is the lower bound (where we start scanning forwards from) - endLedger is the upper bound
Shaptic
requested changes
Dec 22, 2025
| gopkg.in/yaml.v3 v3.0.1 // indirect | ||
| ) | ||
|
|
||
| replace github.com/stellar/go-stellar-sdk => ../go-stellar-sdk |
| var cursorRange protocol.CursorRange | ||
| var validationLedger uint32 // The ledger to validate against retention window | ||
|
|
||
| if isDescending { |
Contributor
There was a problem hiding this comment.
I do not like the complexity that this "feature" introduces for to an already complicated and fragile method. Can you provide a use case where it is valuable to see events in descending order? By their very nature events are meant to be consumed in chronological order.
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.
Summary
orderfield to getEvents pagination options"asc"(default) and"desc"valuesDependencies
This PR depends on: stellar/go-stellar-sdk#5888
The go.mod currently uses a local replace directive pointing to the go-stellar-sdk branch. Once the go-stellar-sdk PR is merged, this will be updated to use the released version.
Changes
EventReader.GetEvents()to accept order parameterprotocol.EventOrdertypes from go-stellar-sdkORDER BY id DESC)Usage
{ "startLedger": 1000, "pagination": { "limit": 10, "order": "desc" }, "filters": [...] }Test plan
Closes #575
🤖 Generated with Claude Code