-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Support query txs' TotalCount in GET /txs #3942
Comments
Agreed the result should include a |
What about a |
Ohhh wait, |
We have got the solution already. @jackzampolin @alexanderbez |
The standard result of REST paging query should contain several fields:
So, I want to add a type to hold these information. type SearchTxsPageableResult struct {
TotalCount int `json:"total_count"`
Number int `json:"number"`
Page int `json:"page"`
Limit int `json:"limit"`
Data []TxResponse `json:"data"`
}
func SearchTxs(cliCtx context.CLIContext, cdc *codec.Codec,
tags []string, page, limit int) (*sdk.SearchTxsPageableResult, error) {
if len(tags) == 0 {
return nil, errors.New("must declare at least one tag to search")
}
if page <= 0 {
return nil, errors.New("page must greater than 0")
}
if limit <= 0 {
return nil, errors.New("limit must greater than 0")
}
// XXX: implement ANY
query := strings.Join(tags, " AND ")
// get the node
node, err := cliCtx.GetNode()
if err != nil {
return nil, err
}
prove := !cliCtx.TrustNode
res, err := node.TxSearch(query, prove, page, limit)
if err != nil {
return nil, err
}
if prove {
for _, tx := range res.Txs {
err := ValidateTxResult(cliCtx, tx)
if err != nil {
return nil, err
}
}
}
info, err := FormatTxResults(cdc, res.Txs)
if err != nil {
return nil, err
}
result := sdk.NewSearchTxsPageableResult(
res.TotalCount, len(info), page, limit, info)
return &result, nil
} |
@yangyanqing I agree, though I'd prefer |
Parameter in spring-boot named such as Thanks for your suggestion ! @alessio |
Oh yeah, total pages is quite important. Can we get that too? |
Great idea ! I had commit it. @alessio type SearchTxsResult struct {
TotalCount int `json:"total_count"`
Count int `json:"count"`
PageNumber int `json:"page_number"`
PageCount int `json:"page_count"`
Limit int `json:"limit"`
Txs []TxResponse `json:"txs"`
}
func NewSearchTxsResult(totalCount, count, page, limit int, txs []TxResponse) SearchTxsResult {
return SearchTxsResult{
TotalCount: totalCount,
Count: count,
PageNumber: page,
PageCount: int(math.Ceil(float64(totalCount) / float64(limit))),
Limit: limit,
Txs: txs,
}
} |
Use GET /txs to query txs that match the tags, it just returns the array of txs.
I see the return of following function contains the count of all target txs, why don't put the TotalCount field in the response, it will help to calculate pagination:
The text was updated successfully, but these errors were encountered: