-
Notifications
You must be signed in to change notification settings - Fork 608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Pagination to Pool With Filter Query #3563
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a928e56
Add Pagination to filter pool query
mattverse cf9ac4a
Use Filtered Pagination
mattverse 9088b82
Add logic for offset in pagination
mattverse aee1d0c
Return false on response
mattverse cc83286
Bug fix
mattverse 79eecfc
Refactors for clean code
mattverse c78ee5d
Remove snake cases
mattverse 18f9284
Fix typos
mattverse 0f9b9e8
Clean more code
mattverse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,18 +158,9 @@ func (q Querier) CalcJoinPoolShares(ctx context.Context, req *types.QueryCalcJoi | |
|
||
// PoolsWithFilter query allows to query pools with specific parameters | ||
func (q Querier) PoolsWithFilter(ctx context.Context, req *types.QueryPoolsWithFilterRequest) (*types.QueryPoolsWithFilterResponse, error) { | ||
res, err := q.Pools(ctx, &types.QueryPoolsRequest{ | ||
Pagination: &query.PageRequest{}, | ||
}) | ||
sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
pools := res.Pools | ||
|
||
var response = []*codectypes.Any{} | ||
store := sdkCtx.KVStore(q.Keeper.storeKey) | ||
poolStore := prefix.NewStore(store, types.KeyPrefixPools) | ||
|
||
// set filters | ||
min_liquidity := req.MinLiquidity | ||
|
@@ -184,14 +175,14 @@ func (q Querier) PoolsWithFilter(ctx context.Context, req *types.QueryPoolsWithF | |
checks_needed++ | ||
} | ||
|
||
for _, p := range pools { | ||
var response = []*codectypes.Any{} | ||
pageRes, err := query.FilteredPaginate(poolStore, req.Pagination, func(_, value []byte, accumulate bool) (bool, error) { | ||
var checks = 0 | ||
var pool types.PoolI | ||
|
||
err := q.cdc.UnpackAny(p, &pool) | ||
pool, err := q.Keeper.UnmarshalPool(value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where does this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It comes from the FilteredPagination method, where it iterates over the given kv store! |
||
if err != nil { | ||
return nil, sdkerrors.ErrUnpackAny | ||
return false, err | ||
} | ||
|
||
poolId := pool.GetId() | ||
|
||
// if liquidity specified in request | ||
|
@@ -226,23 +217,34 @@ func (q Querier) PoolsWithFilter(ctx context.Context, req *types.QueryPoolsWithF | |
if pool_type != "" { | ||
poolType, err := q.GetPoolType(sdkCtx, poolId) | ||
if err != nil { | ||
return nil, types.ErrPoolNotFound | ||
return false, types.ErrPoolNotFound | ||
} | ||
|
||
if poolType == pool_type { | ||
checks++ | ||
} else { | ||
continue | ||
return false, nil | ||
} | ||
} | ||
|
||
if checks == checks_needed { | ||
response = append(response, p) | ||
any, err := codectypes.NewAnyWithValue(pool) | ||
if err != nil { | ||
return false, err | ||
} | ||
response = append(response, any) | ||
} | ||
|
||
return true, nil | ||
}) | ||
|
||
if err != nil { | ||
return nil, status.Error(codes.Internal, err.Error()) | ||
} | ||
|
||
return &types.QueryPoolsWithFilterResponse{ | ||
Pools: response, | ||
Pools: response, | ||
Pagination: pageRes, | ||
}, nil | ||
} | ||
|
||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
FilteredPaginate
instead ofPaginate
method allows us to iterate until pagination count has been reachedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cosmos/cosmos-sdk#12242
We can backport the fix for that to clean this up a little if we want.
(Or just copy/paste cosmos/cosmos-sdk#12253 into osmoutils)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was also checking generic pagination as well! Sad that we don't have it yet. I say we refactor this to use generic pagination later on when it gets backported and for now leave as is