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:
Marko
2019-12-10 12:40:01 +01:00
committed by GitHub
parent 6b1fef7f4d
commit dfebac86f7
26 changed files with 428 additions and 451 deletions
+7 -7
View File
@@ -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()