Moved ethutil => common
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
package trie
|
||||
|
||||
import "github.com/ethereum/go-ethereum/ethutil"
|
||||
import "github.com/ethereum/go-ethereum/common"
|
||||
|
||||
type HashNode struct {
|
||||
key []byte
|
||||
@ -22,4 +22,4 @@ func (self *HashNode) Hash() interface{} {
|
||||
// These methods will never be called but we have to satisfy Node interface
|
||||
func (self *HashNode) Value() Node { return nil }
|
||||
func (self *HashNode) Dirty() bool { return true }
|
||||
func (self *HashNode) Copy(t *Trie) Node { return NewHash(ethutil.CopyBytes(self.key), t) }
|
||||
func (self *HashNode) Copy(t *Trie) Node { return NewHash(common.CopyBytes(self.key), t) }
|
||||
|
@ -1,6 +1,6 @@
|
||||
package trie
|
||||
|
||||
import "github.com/ethereum/go-ethereum/ethutil"
|
||||
import "github.com/ethereum/go-ethereum/common"
|
||||
|
||||
type ShortNode struct {
|
||||
trie *Trie
|
||||
@ -19,7 +19,7 @@ func (self *ShortNode) Value() Node {
|
||||
func (self *ShortNode) Dirty() bool { return true }
|
||||
func (self *ShortNode) Copy(t *Trie) Node {
|
||||
node := &ShortNode{t, nil, self.value.Copy(t)}
|
||||
node.key = ethutil.CopyBytes(self.key)
|
||||
node.key = common.CopyBytes(self.key)
|
||||
return node
|
||||
}
|
||||
|
||||
|
16
trie/trie.go
16
trie/trie.go
@ -7,7 +7,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
func ParanoiaCheck(t1 *Trie, backend Backend) (bool, *Trie) {
|
||||
@ -39,7 +39,7 @@ func New(root []byte, backend Backend) *Trie {
|
||||
}
|
||||
|
||||
if root != nil {
|
||||
value := ethutil.NewValueFromBytes(trie.cache.Get(root))
|
||||
value := common.NewValueFromBytes(trie.cache.Get(root))
|
||||
trie.root = trie.mknode(value)
|
||||
}
|
||||
|
||||
@ -71,10 +71,10 @@ func (self *Trie) Hash() []byte {
|
||||
if byts, ok := t.([]byte); ok && len(byts) > 0 {
|
||||
hash = byts
|
||||
} else {
|
||||
hash = crypto.Sha3(ethutil.Encode(self.root.RlpData()))
|
||||
hash = crypto.Sha3(common.Encode(self.root.RlpData()))
|
||||
}
|
||||
} else {
|
||||
hash = crypto.Sha3(ethutil.Encode(""))
|
||||
hash = crypto.Sha3(common.Encode(""))
|
||||
}
|
||||
|
||||
if !bytes.Equal(hash, self.roothash) {
|
||||
@ -105,7 +105,7 @@ func (self *Trie) Reset() {
|
||||
revision := self.revisions.Remove(self.revisions.Back()).([]byte)
|
||||
self.roothash = revision
|
||||
}
|
||||
value := ethutil.NewValueFromBytes(self.cache.Get(self.roothash))
|
||||
value := common.NewValueFromBytes(self.cache.Get(self.roothash))
|
||||
self.root = self.mknode(value)
|
||||
}
|
||||
|
||||
@ -294,7 +294,7 @@ func (self *Trie) delete(node Node, key []byte) Node {
|
||||
}
|
||||
|
||||
// casting functions and cache storing
|
||||
func (self *Trie) mknode(value *ethutil.Value) Node {
|
||||
func (self *Trie) mknode(value *common.Value) Node {
|
||||
l := value.Len()
|
||||
switch l {
|
||||
case 0:
|
||||
@ -320,7 +320,7 @@ func (self *Trie) mknode(value *ethutil.Value) Node {
|
||||
func (self *Trie) trans(node Node) Node {
|
||||
switch node := node.(type) {
|
||||
case *HashNode:
|
||||
value := ethutil.NewValueFromBytes(self.cache.Get(node.key))
|
||||
value := common.NewValueFromBytes(self.cache.Get(node.key))
|
||||
return self.mknode(value)
|
||||
default:
|
||||
return node
|
||||
@ -328,7 +328,7 @@ func (self *Trie) trans(node Node) Node {
|
||||
}
|
||||
|
||||
func (self *Trie) store(node Node) interface{} {
|
||||
data := ethutil.Encode(node)
|
||||
data := common.Encode(node)
|
||||
if len(data) >= 32 {
|
||||
key := crypto.Sha3(data)
|
||||
self.cache.Put(key, data)
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
type Db map[string][]byte
|
||||
@ -26,7 +26,7 @@ func NewEmptySecure() *SecureTrie {
|
||||
func TestEmptyTrie(t *testing.T) {
|
||||
trie := NewEmpty()
|
||||
res := trie.Hash()
|
||||
exp := crypto.Sha3(ethutil.Encode(""))
|
||||
exp := crypto.Sha3(common.Encode(""))
|
||||
if !bytes.Equal(res, exp) {
|
||||
t.Errorf("expected %x got %x", exp, res)
|
||||
}
|
||||
@ -39,7 +39,7 @@ func TestInsert(t *testing.T) {
|
||||
trie.UpdateString("dog", "puppy")
|
||||
trie.UpdateString("dogglesworth", "cat")
|
||||
|
||||
exp := ethutil.Hex2Bytes("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3")
|
||||
exp := common.Hex2Bytes("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3")
|
||||
root := trie.Hash()
|
||||
if !bytes.Equal(root, exp) {
|
||||
t.Errorf("exp %x got %x", exp, root)
|
||||
@ -48,7 +48,7 @@ func TestInsert(t *testing.T) {
|
||||
trie = NewEmpty()
|
||||
trie.UpdateString("A", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
||||
|
||||
exp = ethutil.Hex2Bytes("d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab")
|
||||
exp = common.Hex2Bytes("d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab")
|
||||
root = trie.Hash()
|
||||
if !bytes.Equal(root, exp) {
|
||||
t.Errorf("exp %x got %x", exp, root)
|
||||
@ -95,7 +95,7 @@ func TestDelete(t *testing.T) {
|
||||
}
|
||||
|
||||
hash := trie.Hash()
|
||||
exp := ethutil.Hex2Bytes("5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84")
|
||||
exp := common.Hex2Bytes("5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84")
|
||||
if !bytes.Equal(hash, exp) {
|
||||
t.Errorf("expected %x got %x", exp, hash)
|
||||
}
|
||||
@ -119,7 +119,7 @@ func TestEmptyValues(t *testing.T) {
|
||||
}
|
||||
|
||||
hash := trie.Hash()
|
||||
exp := ethutil.Hex2Bytes("5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84")
|
||||
exp := common.Hex2Bytes("5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84")
|
||||
if !bytes.Equal(hash, exp) {
|
||||
t.Errorf("expected %x got %x", exp, hash)
|
||||
}
|
||||
@ -168,7 +168,7 @@ func TestReset(t *testing.T) {
|
||||
}
|
||||
trie.Commit()
|
||||
|
||||
before := ethutil.CopyBytes(trie.roothash)
|
||||
before := common.CopyBytes(trie.roothash)
|
||||
trie.UpdateString("should", "revert")
|
||||
trie.Hash()
|
||||
// Should have no effect
|
||||
@ -177,7 +177,7 @@ func TestReset(t *testing.T) {
|
||||
// ###
|
||||
|
||||
trie.Reset()
|
||||
after := ethutil.CopyBytes(trie.roothash)
|
||||
after := common.CopyBytes(trie.roothash)
|
||||
|
||||
if !bytes.Equal(before, after) {
|
||||
t.Errorf("expected roots to be equal. %x - %x", before, after)
|
||||
@ -272,8 +272,8 @@ func TestLargeData(t *testing.T) {
|
||||
vals := make(map[string]*kv)
|
||||
|
||||
for i := byte(0); i < 255; i++ {
|
||||
value := &kv{ethutil.LeftPadBytes([]byte{i}, 32), []byte{i}, false}
|
||||
value2 := &kv{ethutil.LeftPadBytes([]byte{10, i}, 32), []byte{i}, false}
|
||||
value := &kv{common.LeftPadBytes([]byte{i}, 32), []byte{i}, false}
|
||||
value2 := &kv{common.LeftPadBytes([]byte{10, i}, 32), []byte{i}, false}
|
||||
trie.Update(value.k, value.v)
|
||||
trie.Update(value2.k, value2.v)
|
||||
vals[string(value.k)] = value
|
||||
@ -322,7 +322,7 @@ func TestSecureDelete(t *testing.T) {
|
||||
}
|
||||
|
||||
hash := trie.Hash()
|
||||
exp := ethutil.Hex2Bytes("29b235a58c3c25ab83010c327d5932bcf05324b7d6b1185e650798034783ca9d")
|
||||
exp := common.Hex2Bytes("29b235a58c3c25ab83010c327d5932bcf05324b7d6b1185e650798034783ca9d")
|
||||
if !bytes.Equal(hash, exp) {
|
||||
t.Errorf("expected %x got %x", exp, hash)
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package trie
|
||||
|
||||
import "github.com/ethereum/go-ethereum/ethutil"
|
||||
import "github.com/ethereum/go-ethereum/common"
|
||||
|
||||
type ValueNode struct {
|
||||
trie *Trie
|
||||
@ -10,6 +10,6 @@ type ValueNode struct {
|
||||
func (self *ValueNode) Value() Node { return self } // Best not to call :-)
|
||||
func (self *ValueNode) Val() []byte { return self.data }
|
||||
func (self *ValueNode) Dirty() bool { return true }
|
||||
func (self *ValueNode) Copy(t *Trie) Node { return &ValueNode{t, ethutil.CopyBytes(self.data)} }
|
||||
func (self *ValueNode) Copy(t *Trie) Node { return &ValueNode{t, common.CopyBytes(self.data)} }
|
||||
func (self *ValueNode) RlpData() interface{} { return self.data }
|
||||
func (self *ValueNode) Hash() interface{} { return self.data }
|
||||
|
Reference in New Issue
Block a user