Browse Source

rpc: support EXISTS operator in /tx_search query (#4979)

Closes #4763

* check for Error after for loop ends

so we don't silently ignore errors, which would lead to clients getting
incomplete results

Refs https://github.com/tendermint/tendermint/pull/4979/files#r436511572
pull/4991/head
Anton Kaliaev 5 years ago
committed by GitHub
parent
commit
6ec58f1560
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 2 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +4
    -2
      rpc/swagger/swagger.yaml
  3. +32
    -0
      state/txindex/kv/kv.go
  4. +4
    -0
      state/txindex/kv/kv_test.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -69,6 +69,7 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
- [evidence] [\#4532](https://github.com/tendermint/tendermint/pull/4532) Handle evidence from light clients (@melekes)
- [light] [\#4532](https://github.com/tendermint/tendermint/pull/4532) Submit conflicting headers, if any, to a full node & all witnesses (@melekes)
- [rpc] [\#4532](https://github.com/tendermint/tendermint/pull/4923) Support `BlockByHash` query (@fedekunze)
- [rpc] \#4979 Support EXISTS operator in `/tx_search` query (@melekes)
- [p2p] \#4981 Expose `SaveAs` func on NodeKey (@melekes)
### IMPROVEMENTS:


+ 4
- 2
rpc/swagger/swagger.yaml View File

@ -833,6 +833,10 @@ paths:
/tx_search:
get:
summary: Search for transactions
description: |
Search for transactions w/ their results.
See /subscribe for the query syntax.
operationId: tx_search
parameters:
- in: query
@ -876,8 +880,6 @@ paths:
example: "asc"
tags:
- Info
description: |
Get list of unconfirmed transactions
responses:
200:
description: List of unconfirmed transactions


+ 32
- 0
state/txindex/kv/kv.go View File

@ -425,6 +425,32 @@ func (txi *TxIndex) match(
default:
}
}
if err := it.Error(); err != nil {
panic(err)
}
case c.Op == query.OpExists:
// XXX: can't use startKeyBz here because c.Operand is nil
// (e.g. "account.owner/<nil>/" won't match w/ a single row)
it, err := dbm.IteratePrefix(txi.store, startKey(c.CompositeKey))
if err != nil {
panic(err)
}
defer it.Close()
for ; it.Valid(); it.Next() {
tmpHashes[string(it.Value())] = it.Value()
// Potentially exit early.
select {
case <-ctx.Done():
break
default:
}
}
if err := it.Error(); err != nil {
panic(err)
}
case c.Op == query.OpContains:
// XXX: startKey does not apply here.
@ -452,6 +478,9 @@ func (txi *TxIndex) match(
default:
}
}
if err := it.Error(); err != nil {
panic(err)
}
default:
panic("other operators should be handled already")
}
@ -553,6 +582,9 @@ LOOP:
default:
}
}
if err := it.Error(); err != nil {
panic(err)
}
if len(tmpHashes) == 0 || firstRun {
// Either:


+ 4
- 0
state/txindex/kv/kv_test.go View File

@ -117,6 +117,10 @@ func TestTxSearch(t *testing.T) {
{"account.owner CONTAINS 'Vlad'", 0},
// search using the wrong key (of numeric type) using CONTAINS
{"account.number CONTAINS 'Iv'", 0},
// search using EXISTS
{"account.number EXISTS", 1},
// search using EXISTS for non existing key
{"account.date EXISTS", 0},
}
ctx := context.Background()


Loading…
Cancel
Save