-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat: implement pagination for x/wasm query #85
Conversation
tps:389 |
x/wasm/client/utils/utils.go
Outdated
if err != nil { | ||
return pageKey, offset, limit, page, countTotal, err | ||
} | ||
if offset <= 0 { |
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.
other than here, used else if
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.
x/wasm/client/cli/query.go
Outdated
if err != nil { | ||
return err | ||
} | ||
|
||
route := fmt.Sprintf("custom/%s/%s/%s", types.QuerierRoute, keeper.QueryContractHistory, addr.String()) |
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 think address information is now included in the data field so that we can diet route path.
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.
yes! it removed.
x/wasm/client/rest/query.go
Outdated
data := &types.QueryCodesRequest{ | ||
Pagination: pageReq, | ||
} | ||
bs, err := cliCtx.Codec.MarshalJSON(data) | ||
if err != nil { | ||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
|
||
res, height, err := cliCtx.QueryWithData(route, bs) |
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.
Can we reduce the duplicate codes?
cli/query.go#L60-L68
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.
It is summarized in utils.
x/wasm/client/rest/query.go
Outdated
return | ||
} | ||
|
||
data := &types.QueryContractsByCodeRequest{ |
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.
ditto
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.
ditto
x/wasm/client/rest/query.go
Outdated
return | ||
} | ||
|
||
data := &types.QueryContractHistoryRequest{ |
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.
ditto
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.
ditto
}, nil | ||
} | ||
|
||
func ParseHTTPArgs(r *http.Request) (pageKey string, offset, limit, page uint64, countTotal bool, err error) { |
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.
The pagination utility for HTTP args does already exist. Can we use it for API consistency?
https://github.com/line/lbm-sdk/blob/develop/types/rest/rest.go#L382
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.
The limit and page could be parseed from the already existing ParseHTTPArgs.
tps:309 |
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 have left a minor comment.
x/wasm/internal/keeper/keeper.go
Outdated
|
||
// NOTE: This function is implemented in cosmos-sdk v0.40.0. | ||
// If you want to update cosmos-sdk to 0.40.0 or later, you can use the sdk function. | ||
func FilteredPaginate( |
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 think this function is part of the query feature, so seems to be better to move it to keeper/querier.go
tps:304 |
x/wasm/client/utils/utils.go
Outdated
page, err = strconv.ParseUint(pageStr, 10, 64) | ||
if err != nil { | ||
return pageKey, offset, limit, page, countTotal, err | ||
} else if page <= 0 { |
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.
Minor comment. As the previous doc says, the following suggestion is better.
} else if page <= 0 { | |
} | |
if page <= 0 { |
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.
Question: does page index start from 1, not 0?
x/wasm/client/utils/utils.go
Outdated
limit, err = strconv.ParseUint(limitStr, 10, 64) | ||
if err != nil { | ||
return pageKey, offset, limit, page, countTotal, err | ||
} else if limit <= 0 { |
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.
} else if limit <= 0 { | |
} | |
if limit <= 0 { |
ditto
tps:364 |
tps:340 |
tps:358 |
The original is the PR #85. cherry-pick from v1/develop by Jiyong Ha<[email protected]>
* feat(wasm): add pagination for rest api The original is the PR #85. cherry-pick from v1/develop by Jiyong Ha<[email protected]> * feat(wasm): make hardcoded params to gov params The original is the PR #86. with excessive gas consumption issue needs further modification. cherry-pick from v1/develop by Jiyong Ha<[email protected]> * test(wasm): adjust gas by gov params Limit values are greatly eased due to the known issue of gas consumption. * chore: go fmt * chore: fix typo Co-authored-by: shiki <[email protected]>
Closes: https://github.com/line/link-modules/issues/85
Ref: https://github.com/line/link-modules/pull/87
Description
I changed the structure of contract_history store and added pagination query.
In cosmos-sdk v0.40.0 and later, the sdk defines a flag and protobuf for pagination, but this is not implemented in the current version, so I added my own flag by referring to the following PR.
https://github.com/cosmos/cosmos-sdk/blob/f3e4964f2f9cdf5d65c819d689950bffec728c65/types/query/filtered_pagination.go#L17
Format
Motivation and context
How has this been tested?
Checklist: