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
This commit is contained in:
Anton Kaliaev
2020-06-09 09:30:05 +04:00
committed by GitHub
parent a89f2581fc
commit 6ec58f1560
4 changed files with 41 additions and 2 deletions
+32
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
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()