mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-25 01:14:28 +00:00
* Updated event sequencing and added query keyword * code cosmetics * Documentation update * Added per event indexing and querying to txindexer * rpc test fix * Added support for older versions where event sequencing is not supported * Added support for old versions to tx indexer * Added RPC match flag, fixed bugs in tx indexer, added tests * Removed reference to match.events from the docs * Openapi update * Added height deduplication Co-authored-by: Thane Thomson <connect@thanethomson.com> Co-authored-by: Anca Zamfir <zamfiranca@gmail.com> Co-authored-by: Sergio Mena <sergio@informal.systems> Co-authored-by: Romain Ruetschi <romain.ruetschi@gmail.com> Co-authored-by: Thane Thomson <connect@thanethomson.com>
77 lines
1.8 KiB
Go
77 lines
1.8 KiB
Go
package kv
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/google/orderedcode"
|
|
"github.com/tendermint/tendermint/libs/pubsub/query"
|
|
"github.com/tendermint/tendermint/types"
|
|
)
|
|
|
|
// IntInSlice returns true if a is found in the list.
|
|
func intInSlice(a int, list []int) bool {
|
|
for _, b := range list {
|
|
if b == a {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func dedupMatchEvents(conditions []query.Condition) ([]query.Condition, bool) {
|
|
var dedupConditions []query.Condition
|
|
matchEvents := false
|
|
for i, c := range conditions {
|
|
if c.CompositeKey == types.MatchEventKey {
|
|
// Match events should be added only via RPC as the very first query condition
|
|
if i == 0 {
|
|
dedupConditions = append(dedupConditions, c)
|
|
matchEvents = true
|
|
}
|
|
} else {
|
|
dedupConditions = append(dedupConditions, c)
|
|
}
|
|
|
|
}
|
|
return dedupConditions, matchEvents
|
|
}
|
|
|
|
func ParseEventSeqFromEventKey(key []byte) (int64, error) {
|
|
var (
|
|
compositeKey, typ, eventValue string
|
|
height int64
|
|
eventSeq int64
|
|
)
|
|
|
|
remaining, err := orderedcode.Parse(string(key), &compositeKey, &eventValue, &height, &typ, &eventSeq)
|
|
if err != nil {
|
|
return 0, fmt.Errorf("failed to parse event key: %w", err)
|
|
}
|
|
|
|
if len(remaining) != 0 {
|
|
return 0, fmt.Errorf("unexpected remainder in key: %s", remaining)
|
|
}
|
|
|
|
return eventSeq, nil
|
|
}
|
|
func dedupHeight(conditions []query.Condition) (dedupConditions []query.Condition, height int64, idx int) {
|
|
found := false
|
|
idx = -1
|
|
height = 0
|
|
for i, c := range conditions {
|
|
if c.CompositeKey == types.TxHeightKey && c.Op == query.OpEqual {
|
|
if found {
|
|
continue
|
|
} else {
|
|
dedupConditions = append(dedupConditions, c)
|
|
height = c.Operand.(int64)
|
|
found = true
|
|
idx = i
|
|
}
|
|
} else {
|
|
dedupConditions = append(dedupConditions, c)
|
|
}
|
|
}
|
|
return
|
|
}
|