Skip to content
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 min-height and max-height filters to TxSearch #5648

Merged
merged 3 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ for JSON encoding.
* (types) [\#5585](https://github.com/cosmos/cosmos-sdk/pull/5585) IBC additions:
* `Coin` denomination max lenght has been increased to 32.
* Added `CapabilityKey` alias for `StoreKey` to match IBC spec.
* (rest) [\#5648](https://github.com/cosmos/cosmos-sdk/pull/5648) Enhance /txs usability:
* Add `tx.minheight` key to filter transaction with an inclusive minimum block height
* Add `tx.maxheight` key to filter transaction with an inclusive maximum block height

## [v0.38.1] - 2020-02-11

Expand Down
10 changes: 10 additions & 0 deletions client/lcd/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ paths:
description: Maximum number of items per page
type: integer
x-example: 1
- in: query
name: tx.minheight
type: integer
description: "transactions on blocks with height greater or equal this value"
x-example: 25
- in: query
name: tx.maxheight
type: integer
description: "transactions on blocks with height less than or equal this value"
x-example: 800000
responses:
200:
description: All txs matching the provided events
Expand Down
6 changes: 6 additions & 0 deletions types/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
const (
DefaultPage = 1
DefaultLimit = 30 // should be consistent with tendermint/tendermint/rpc/core/pipe.go:19
TxMinHeightKey = "tx.minheight" // Inclusive minimum height filter
TxMaxHeightKey = "tx.maxheight" // Inclusive maximum height filter
)

// ResponseWithHeight defines a response object type that wraps an original
Expand Down Expand Up @@ -337,6 +339,10 @@ func ParseHTTPArgsWithLimit(r *http.Request, defaultLimit int) (tags []string, p
var tag string
if key == types.TxHeightKey {
tag = fmt.Sprintf("%s=%s", key, value)
} else if key == TxMinHeightKey {
tag = fmt.Sprintf("%s>=%s", types.TxHeightKey, value)
} else if key == TxMaxHeightKey {
tag = fmt.Sprintf("%s<=%s", types.TxHeightKey, value)
} else {
tag = fmt.Sprintf("%s='%s'", key, value)
}
Expand Down
3 changes: 3 additions & 0 deletions types/rest/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func TestParseHTTPArgs(t *testing.T) {
reqE2 := mustNewRequest(t, "", "/?limit=-1", nil)
req4 := mustNewRequest(t, "", "/?foo=faa", nil)

reqTxH := mustNewRequest(t, "", "/?tx.minheight=12&tx.maxheight=14", nil)

tests := []struct {
name string
req *http.Request
Expand All @@ -89,6 +91,7 @@ func TestParseHTTPArgs(t *testing.T) {
{"error limit 0", reqE2, httptest.NewRecorder(), []string{}, DefaultPage, DefaultLimit, true},

{"tags", req4, httptest.NewRecorder(), []string{"foo='faa'"}, DefaultPage, DefaultLimit, false},
{"tags", reqTxH, httptest.NewRecorder(), []string{"tx.height>=12", "tx.height<=14"}, DefaultPage, DefaultLimit, false},
}
for _, tt := range tests {
tt := tt
Expand Down