mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-17 12:46:16 +00:00
## NOTE: this pr exclusively runs commands from the makefile found here This PR ONLY runs `make format` ... then `make mockery` Its purpose is to ensure that the review scope of other PR's, which changed .go files and thus triggered the linter that only runs conditionally, have smaller review scopes, and should be merged before: https://github.com/tendermint/tendermint/pull/9738 https://github.com/tendermint/tendermint/pull/9739 https://github.com/tendermint/tendermint/pull/9742 --- #### PR checklist - [x] Tests written/updated, or no tests needed - [x] `CHANGELOG_PENDING.md` updated, or no changelog entry needed - [x] Updated relevant documentation (`docs/`) and code comments, or no documentation updates needed
98 lines
1.9 KiB
Go
98 lines
1.9 KiB
Go
package kv
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"github.com/google/orderedcode"
|
|
|
|
"github.com/tendermint/tendermint/libs/pubsub/query/syntax"
|
|
"github.com/tendermint/tendermint/types"
|
|
)
|
|
|
|
func intInSlice(a int, list []int) bool {
|
|
for _, b := range list {
|
|
if b == a {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func int64FromBytes(bz []byte) int64 {
|
|
v, _ := binary.Varint(bz)
|
|
return v
|
|
}
|
|
|
|
func int64ToBytes(i int64) []byte {
|
|
buf := make([]byte, binary.MaxVarintLen64)
|
|
n := binary.PutVarint(buf, i)
|
|
return buf[:n]
|
|
}
|
|
|
|
func heightKey(height int64) ([]byte, error) {
|
|
return orderedcode.Append(
|
|
nil,
|
|
types.BlockHeightKey,
|
|
height,
|
|
)
|
|
}
|
|
|
|
func eventKey(compositeKey, typ, eventValue string, height int64) ([]byte, error) {
|
|
return orderedcode.Append(
|
|
nil,
|
|
compositeKey,
|
|
eventValue,
|
|
height,
|
|
typ,
|
|
)
|
|
}
|
|
|
|
func parseValueFromPrimaryKey(key []byte) (string, error) {
|
|
var (
|
|
compositeKey string
|
|
height int64
|
|
)
|
|
|
|
remaining, err := orderedcode.Parse(string(key), &compositeKey, &height)
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to parse event key: %w", err)
|
|
}
|
|
|
|
if len(remaining) != 0 {
|
|
return "", fmt.Errorf("unexpected remainder in key: %s", remaining)
|
|
}
|
|
|
|
return strconv.FormatInt(height, 10), nil
|
|
}
|
|
|
|
func parseValueFromEventKey(key []byte) (string, error) {
|
|
var (
|
|
compositeKey, typ, eventValue string
|
|
height int64
|
|
)
|
|
|
|
remaining, err := orderedcode.Parse(string(key), &compositeKey, &eventValue, &height, &typ)
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to parse event key: %w", err)
|
|
}
|
|
|
|
if len(remaining) != 0 {
|
|
return "", fmt.Errorf("unexpected remainder in key: %s", remaining)
|
|
}
|
|
|
|
return eventValue, nil
|
|
}
|
|
|
|
func lookForHeight(conditions []syntax.Condition) (int64, bool) {
|
|
for _, c := range conditions {
|
|
if c.Tag == types.BlockHeightKey && c.Op == syntax.TEq {
|
|
return int64(c.Arg.Number()), true
|
|
}
|
|
}
|
|
|
|
return 0, false
|
|
}
|