mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-30 11:45:37 +00:00
libs/common: refactor libs/common 01 (#4230)
* libs/common: Refactor libs/common 01 Signed-off-by: Marko Baricevic <marbar3778@yahoo.com> * regenerate proto files, move intslice to where its used * update kv.KVPair(s) to kv.Pair(s) * add changelog entry * make intInSlice private
This commit is contained in:
@@ -5,14 +5,14 @@ import (
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
"github.com/tendermint/tendermint/libs/kv"
|
||||
)
|
||||
|
||||
// Merkle tree from a map.
|
||||
// Leaves are `hash(key) | hash(value)`.
|
||||
// Leaves are sorted before Merkle hashing.
|
||||
type simpleMap struct {
|
||||
kvs cmn.KVPairs
|
||||
kvs kv.Pairs
|
||||
sorted bool
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func (sm *simpleMap) Set(key string, value []byte) {
|
||||
// and make a determination to fetch or not.
|
||||
vhash := tmhash.Sum(value)
|
||||
|
||||
sm.kvs = append(sm.kvs, cmn.KVPair{
|
||||
sm.kvs = append(sm.kvs, kv.Pair{
|
||||
Key: []byte(key),
|
||||
Value: vhash,
|
||||
})
|
||||
@@ -56,9 +56,9 @@ func (sm *simpleMap) Sort() {
|
||||
|
||||
// Returns a copy of sorted KVPairs.
|
||||
// NOTE these contain the hashed key and value.
|
||||
func (sm *simpleMap) KVPairs() cmn.KVPairs {
|
||||
func (sm *simpleMap) KVPairs() kv.Pairs {
|
||||
sm.Sort()
|
||||
kvs := make(cmn.KVPairs, len(sm.kvs))
|
||||
kvs := make(kv.Pairs, len(sm.kvs))
|
||||
copy(kvs, sm.kvs)
|
||||
return kvs
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func (sm *simpleMap) KVPairs() cmn.KVPairs {
|
||||
// A local extension to KVPair that can be hashed.
|
||||
// Key and value are length prefixed and concatenated,
|
||||
// then hashed.
|
||||
type KVPair cmn.KVPair
|
||||
type KVPair kv.Pair
|
||||
|
||||
// Bytes returns key || value, with both the
|
||||
// key and value length prefixed.
|
||||
@@ -85,7 +85,7 @@ func (kv KVPair) Bytes() []byte {
|
||||
return b.Bytes()
|
||||
}
|
||||
|
||||
func hashKVPairs(kvs cmn.KVPairs) []byte {
|
||||
func hashKVPairs(kvs kv.Pairs) []byte {
|
||||
kvsH := make([][]byte, len(kvs))
|
||||
for i, kvp := range kvs {
|
||||
kvsH[i] = KVPair(kvp).Bytes()
|
||||
|
||||
Reference in New Issue
Block a user