Skip to content

Commit fa46bbe

Browse files
committed
fix(x/market): apply pagination fixes to all query handlers
1 parent efd7c85 commit fa46bbe

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

x/market/keeper/grpc_query.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,19 @@ func (k Querier) Bids(c context.Context, req *types.QueryBidsRequest) (*types.Qu
194194
var key []byte
195195
var unsolicited []byte
196196
var err error
197-
states, searchPrefix, key, unsolicited, err = query.DecodePaginationKey(req.Pagination.Key)
197+
198+
// Accept both raw and base64-encoded keys: try raw first, then base64.
199+
paginationKeyBytes := req.Pagination.Key
200+
states, searchPrefix, key, unsolicited, err = query.DecodePaginationKey(paginationKeyBytes)
201+
if err != nil {
202+
if decoded, decErr := base64.StdEncoding.DecodeString(string(req.Pagination.Key)); decErr == nil {
203+
states, searchPrefix, key, unsolicited, err = query.DecodePaginationKey(decoded)
204+
}
205+
}
198206
if err != nil {
207+
if errors.Is(err, query.ErrInvalidPaginationKey) {
208+
return nil, status.Error(codes.InvalidArgument, err.Error())
209+
}
199210
return nil, status.Error(codes.Internal, err.Error())
200211
}
201212

@@ -204,7 +215,7 @@ func (k Querier) Bids(c context.Context, req *types.QueryBidsRequest) (*types.Qu
204215
}
205216
req.Pagination.Key = key
206217

207-
if unsolicited[1] == 1 {
218+
if unsolicited[0] == 1 {
208219
reverseSearch = true
209220
}
210221
} else if req.Filters.State != "" {
@@ -348,8 +359,19 @@ func (k Querier) Leases(c context.Context, req *types.QueryLeasesRequest) (*type
348359
var key []byte
349360
var unsolicited []byte
350361
var err error
351-
states, searchPrefix, key, unsolicited, err = query.DecodePaginationKey(req.Pagination.Key)
362+
363+
// Accept both raw and base64-encoded keys: try raw first, then base64.
364+
paginationKeyBytes := req.Pagination.Key
365+
states, searchPrefix, key, unsolicited, err = query.DecodePaginationKey(paginationKeyBytes)
352366
if err != nil {
367+
if decoded, decErr := base64.StdEncoding.DecodeString(string(req.Pagination.Key)); decErr == nil {
368+
states, searchPrefix, key, unsolicited, err = query.DecodePaginationKey(decoded)
369+
}
370+
}
371+
if err != nil {
372+
if errors.Is(err, query.ErrInvalidPaginationKey) {
373+
return nil, status.Error(codes.InvalidArgument, err.Error())
374+
}
353375
return nil, status.Error(codes.Internal, err.Error())
354376
}
355377

0 commit comments

Comments
 (0)