mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 15:04:22 +00:00
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:
@@ -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:
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user