Files
tendermint/internal/state/indexer/block/kv/util.go
T
d3548eb706 Completed the existing FinalizeBlock PR and rebased to master (#7798)
* Rebased and git-squashed the commits in PR #6546

migrate abci to finalizeBlock

work on abci, proxy and mempool

abciresponse, blok events, indexer, some tests

fix some tests

fix errors

fix errors in abci

fix tests amd errors

* Fixes after rebasing PR#6546

* Restored height to RequestFinalizeBlock & other

* Fixed more UTs

* Fixed kvstore

* More UT fixes

* last TC fixed

* make format

* Update internal/consensus/mempool_test.go

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>

* Addressed @williambanfield's comments

* Fixed UTs

* Addressed last comments from @williambanfield

* make format

Co-authored-by: marbar3778 <marbar3778@yahoo.com>
Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>
2022-02-14 23:41:28 +01:00

98 lines
1.9 KiB
Go

package kv
import (
"encoding/binary"
"fmt"
"strconv"
"github.com/google/orderedcode"
"github.com/tendermint/tendermint/internal/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
}