Browse Source

use go-wire sdk2

pull/1842/head
Ethan Buchman 7 years ago
committed by Anton Kaliaev
parent
commit
cfbb9338bd
No known key found for this signature in database GPG Key ID: 7B6881D965918214
5 changed files with 42 additions and 51 deletions
  1. +19
    -27
      glide.lock
  2. +1
    -0
      glide.yaml
  3. +8
    -8
      merkle/simple_map.go
  4. +6
    -6
      merkle/simple_map_test.go
  5. +8
    -10
      merkle/simple_tree.go

+ 19
- 27
glide.lock View File

@ -1,10 +1,14 @@
hash: 325b2f9c7e84696f88fa88126a22eb1e1e91c2be5f60402d17bfaad6713b33c2
updated: 2017-12-28T18:27:21.247160207-08:00
hash: c2db6960e66e1f56fbce88caec470cbde14701763efb4a26d2f3fabd2f979a96
updated: 2018-01-14T17:26:45.597677436-05:00
imports:
- name: github.com/davecgh/go-spew
version: 04cdfd42973bb9c8589fd6a731800cf222fde1a9
subpackages:
- spew
- name: github.com/fsnotify/fsnotify
version: 4da3e2cfbabc9f751898f250b49f2439785783a1
- name: github.com/go-kit/kit
version: e2b298466b32c7cd5579a9b9b07e968fc9d9452c
version: 953e747656a7bbb5e1f998608b460458958b70cc
subpackages:
- log
- log/level
@ -12,7 +16,7 @@ imports:
- name: github.com/go-logfmt/logfmt
version: 390ab7935ee28ec6b286364bba9b4dd6410cb3d5
- name: github.com/go-stack/stack
version: 817915b46b97fd7bb80e8ab6b69f01a53ac3eebf
version: 259ab82a6cad3992b4e21ff5cac294ccb06474bc
- name: github.com/gogo/protobuf
version: 342cbe0a04158f6dcb03ca0079991a51a4248c02
subpackages:
@ -39,21 +43,15 @@ imports:
- name: github.com/kr/logfmt
version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0
- name: github.com/magiconair/properties
version: 8d7837e64d3c1ee4e54a880c5a920ab4316fc90a
- name: github.com/mattn/go-colorable
version: 6fcc0c1fd9b620311d821b106a400b35dc95c497
- name: github.com/mattn/go-isatty
version: a5cdd64afdee435007ee3e9f6ed4684af949d568
version: 49d762b9817ba1c2e9d0c69183c2b4a8b8f1d934
- name: github.com/mitchellh/mapstructure
version: 06020f85339e21b2478f756a78e295255ffa4d6a
- name: github.com/pelletier/go-buffruneio
version: c37440a7cf42ac63b919c752ca73a85067e05992
- name: github.com/pelletier/go-toml
version: 13d49d4606eb801b8f01ae542b4afc4c6ee3d84a
version: 0131db6d737cfbbfb678f8b7d92e55e27ce46224
- name: github.com/pkg/errors
version: 645ef00459ed84a119197bfb8d8205042c6df63d
- name: github.com/spf13/afero
version: 5660eeed305fe5f69c8fc6cf899132a459a97064
version: 57afd63c68602b63ed976de00dd066ccb3c319db
subpackages:
- mem
- name: github.com/spf13/cast
@ -63,11 +61,11 @@ imports:
- name: github.com/spf13/jwalterweatherman
version: 12bd96e66386c1960ab0f74ced1362f66f552f7b
- name: github.com/spf13/pflag
version: 97afa5e7ca8a08a383cb259e06636b5e2cc7897f
version: 4c012f6dcd9546820e378d0bdda4d8fc772cdfea
- name: github.com/spf13/viper
version: 8ef37cbca71638bf32f3d5e194117d4cb46da163
version: 25b30aa063fc18e48662b86996252eabdcf2f0c7
- name: github.com/syndtr/goleveldb
version: b89cc31ef7977104127d34c1bd31ebd1a9db2199
version: 34011bf325bce385408353a30b101fe5e923eb6e
subpackages:
- leveldb
- leveldb/cache
@ -82,34 +80,28 @@ imports:
- leveldb/table
- leveldb/util
- name: github.com/tendermint/go-wire
version: 27be46e25124ddf775e23317a83647ce62a93f6b
version: b93ebdd4f306833936c243561ec30af3455dc764
subpackages:
- data
- data/base58
- name: github.com/tendermint/log15
version: f91285dece9f4875421b481da3e613d83d44f29b
subpackages:
- term
- name: golang.org/x/crypto
version: edd5e9b0879d13ee6970a50153d85b8fec9f7686
version: 95a4943f35d008beabde8c11e5075a1b714e6419
subpackages:
- ripemd160
- name: golang.org/x/sys
version: 8dbc5d05d6edcc104950cc299a1ce6641235bc86
version: 83801418e1b59fb1880e363299581ee543af32ca
subpackages:
- unix
- name: golang.org/x/text
version: c01e4764d870b77f8abe5096ee19ad20d80e8075
version: e19ae1496984b1c655b8044a65c0300a3c878dd3
subpackages:
- transform
- unicode/norm
- name: gopkg.in/yaml.v2
version: eb3733d160e74a9c7e442f435eb3bea458e1d19f
version: 287cf08546ab5e7e37d55a84f7ed3fd1db036de5
testImports:
- name: github.com/davecgh/go-spew
version: 04cdfd42973bb9c8589fd6a731800cf222fde1a9
subpackages:
- spew
- name: github.com/pmezard/go-difflib
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
subpackages:


+ 1
- 0
glide.yaml View File

@ -16,6 +16,7 @@ import:
- leveldb/errors
- leveldb/opt
- package: github.com/tendermint/go-wire
version: sdk2
subpackages:
- data
- data/base58


+ 8
- 8
merkle/simple_map.go View File

@ -26,7 +26,7 @@ func (sm *SimpleMap) Set(key string, value interface{}) {
if hashable, ok := value.(Hashable); ok {
vBytes = hashable.Hash()
} else {
vBytes = wire.BinaryBytes(value)
vBytes, _ = wire.MarshalBinary(value)
}
sm.kvs = append(sm.kvs, cmn.KVPair{
@ -65,14 +65,14 @@ func (sm *SimpleMap) KVPairs() cmn.KVPairs {
type kvPair cmn.KVPair
func (kv kvPair) Hash() []byte {
hasher, n, err := ripemd160.New(), new(int), new(error)
wire.WriteByteSlice(kv.Key, hasher, n, err)
if *err != nil {
panic(*err)
hasher := ripemd160.New()
err := wire.EncodeByteSlice(hasher, kv.Key)
if err != nil {
panic(err)
}
wire.WriteByteSlice(kv.Value, hasher, n, err)
if *err != nil {
panic(*err)
err = wire.EncodeByteSlice(hasher, kv.Value)
if err != nil {
panic(err)
}
return hasher.Sum(nil)
}


+ 6
- 6
merkle/simple_map_test.go View File

@ -11,37 +11,37 @@ func TestSimpleMap(t *testing.T) {
{
db := NewSimpleMap()
db.Set("key1", "value1")
assert.Equal(t, "3bb53f017d2f5b4f144692aa829a5c245ac2b123", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
assert.Equal(t, "d7df3e1d47fe38b51f8d897a88828026807a86b6", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
}
{
db := NewSimpleMap()
db.Set("key1", "value2")
assert.Equal(t, "14a68db29e3f930ffaafeff5e07c17a439384f39", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
assert.Equal(t, "db415336c9be129ac38259b935a49d8e9c248c88", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
}
{
db := NewSimpleMap()
db.Set("key1", "value1")
db.Set("key2", "value2")
assert.Equal(t, "275c6367f4be335f9c482b6ef72e49c84e3f8bda", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
assert.Equal(t, "fdb900a04c1de42bd3d924fc644e28a4bdce30ce", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
}
{
db := NewSimpleMap()
db.Set("key2", "value2") // NOTE: out of order
db.Set("key1", "value1")
assert.Equal(t, "275c6367f4be335f9c482b6ef72e49c84e3f8bda", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
assert.Equal(t, "fdb900a04c1de42bd3d924fc644e28a4bdce30ce", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
}
{
db := NewSimpleMap()
db.Set("key1", "value1")
db.Set("key2", "value2")
db.Set("key3", "value3")
assert.Equal(t, "48d60701cb4c96916f68a958b3368205ebe3809b", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
assert.Equal(t, "488cfdaea108ef8bd406f6163555752392ae1b4a", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
}
{
db := NewSimpleMap()
db.Set("key2", "value2") // NOTE: out of order
db.Set("key1", "value1")
db.Set("key3", "value3")
assert.Equal(t, "48d60701cb4c96916f68a958b3368205ebe3809b", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
assert.Equal(t, "488cfdaea108ef8bd406f6163555752392ae1b4a", fmt.Sprintf("%x", db.Hash()), "Hash didn't match")
}
}

+ 8
- 10
merkle/simple_tree.go View File

@ -28,17 +28,14 @@ import (
"golang.org/x/crypto/ripemd160"
"github.com/tendermint/go-wire"
. "github.com/tendermint/tmlibs/common"
)
func SimpleHashFromTwoHashes(left []byte, right []byte) []byte {
var n int
var err error
var hasher = ripemd160.New()
wire.WriteByteSlice(left, hasher, &n, &err)
wire.WriteByteSlice(right, hasher, &n, &err)
err := wire.EncodeByteSlice(hasher, left)
err = wire.EncodeByteSlice(hasher, right)
if err != nil {
PanicCrisis(err)
panic(err)
}
return hasher.Sum(nil)
}
@ -68,11 +65,12 @@ func SimpleHashFromBinaries(items []interface{}) []byte {
// General Convenience
func SimpleHashFromBinary(item interface{}) []byte {
hasher, n, err := ripemd160.New(), new(int), new(error)
wire.WriteBinary(item, hasher, n, err)
if *err != nil {
PanicCrisis(err)
hasher := ripemd160.New()
bz, err := wire.MarshalBinary(item)
if err != nil {
panic(err)
}
hasher.Write(bz)
return hasher.Sum(nil)
}


Loading…
Cancel
Save