Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
* [#19833](https://github.com/cosmos/cosmos-sdk/pull/19833) Fix some places in which we call Remove inside a Walk.
* [#19851](https://github.com/cosmos/cosmos-sdk/pull/19851) Fix some places in which we call Remove inside a Walk (x/staking and x/gov).
* [#20631](https://github.com/cosmos/cosmos-sdk/pull/20631) Fix json parsing in the wait-tx command.
* [#20939](https://github.com/cosmos/cosmos-sdk/pull/20939) Fix collection reverse iterator to include `pagination.key` in the result.

### API Breaking Changes

Expand Down
10 changes: 5 additions & 5 deletions types/query/collections_pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,11 @@ func encodeCollKey[K, V any, C Collection[K, V]](coll C, key K) ([]byte, error)
func getCollIter[K, V any, C Collection[K, V]](ctx context.Context, coll C, prefix, start []byte, reverse bool) (collections.Iterator[K, V], error) {
// TODO: maybe can be simplified
if reverse {
var end []byte
if prefix != nil {
start = storetypes.PrefixEndBytes(append(prefix, start...))
end = prefix
}
// if we are in reverse mode, we need to increase the start key
// to include the start key in the iteration.
start = storetypes.PrefixEndBytes(append(prefix, start...))
end := prefix
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is not needed, just pass prefix to IterateRaw in the place of end. Although we may want to keep it for readability

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea I also think it's good for readability


return coll.IterateRaw(ctx, end, start, collections.OrderDescending)
}
var end []byte
Expand Down
10 changes: 10 additions & 0 deletions types/query/collections_pagination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ func TestCollectionPagination(t *testing.T) {
},
expResults: createResults(299, 200),
},
"with key and reverse": {
req: &PageRequest{
Key: encodeKey(199),
Reverse: true,
},
expResp: &PageResponse{
NextKey: encodeKey(99),
},
expResults: createResults(199, 100),
},
"with offset and count total": {
req: &PageRequest{
Offset: 50,
Expand Down