From 56dbba9aaecc0fe633c59aee489cb242224795b0 Mon Sep 17 00:00:00 2001 From: Christopher Franko Date: Tue, 3 Nov 2015 19:00:40 -0500 Subject: [PATCH] removed files --- trie/cache.go | 78 --------------------------------------- trie/fullnode.go | 94 ----------------------------------------------- trie/hashnode.go | 46 ----------------------- trie/shortnode.go | 57 ---------------------------- trie/valuenode.go | 42 --------------------- 5 files changed, 317 deletions(-) delete mode 100644 trie/cache.go delete mode 100644 trie/fullnode.go delete mode 100644 trie/hashnode.go delete mode 100644 trie/shortnode.go delete mode 100644 trie/valuenode.go diff --git a/trie/cache.go b/trie/cache.go deleted file mode 100644 index a5ca1d3377..0000000000 --- a/trie/cache.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2014 The go-ethereum Authors && Copyright 2015 go-expanse Authors -// This file is part of the go-expanse library. -// -// The go-expanse library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-expanse library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-expanse library. If not, see . - -package trie - -import ( - "github.com/expanse-project/go-expanse/ethdb" - "github.com/expanse-project/go-expanse/logger/glog" - "github.com/syndtr/goleveldb/leveldb" -) - -type Backend interface { - Get([]byte) ([]byte, error) - Put([]byte, []byte) error -} - -type Cache struct { - batch *leveldb.Batch - store map[string][]byte - backend Backend -} - -func NewCache(backend Backend) *Cache { - return &Cache{new(leveldb.Batch), make(map[string][]byte), backend} -} - -func (self *Cache) Get(key []byte) []byte { - data := self.store[string(key)] - if data == nil { - data, _ = self.backend.Get(key) - } - - return data -} - -func (self *Cache) Put(key []byte, data []byte) { - self.batch.Put(key, data) - self.store[string(key)] = data -} - -// Flush flushes the trie to the backing layer. If this is a leveldb instance -// we'll use a batched write, otherwise we'll use regular put. -func (self *Cache) Flush() { - if db, ok := self.backend.(*ethdb.LDBDatabase); ok { - if err := db.LDB().Write(self.batch, nil); err != nil { - glog.Fatal("db write err:", err) - } - } else { - for k, v := range self.store { - self.backend.Put([]byte(k), v) - } - } -} - -func (self *Cache) Copy() *Cache { - cache := NewCache(self.backend) - for k, v := range self.store { - cache.store[k] = v - } - return cache -} - -func (self *Cache) Reset() { - //self.store = make(map[string][]byte) -} diff --git a/trie/fullnode.go b/trie/fullnode.go deleted file mode 100644 index 09b29dcc08..0000000000 --- a/trie/fullnode.go +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2014 The go-ethereum Authors && Copyright 2015 go-expanse Authors -// This file is part of the go-expanse library. -// -// The go-expanse library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-expanse library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-expanse library. If not, see . - -package trie - -type FullNode struct { - trie *Trie - nodes [17]Node - dirty bool -} - -func NewFullNode(t *Trie) *FullNode { - return &FullNode{trie: t} -} - -func (self *FullNode) Dirty() bool { return self.dirty } -func (self *FullNode) Value() Node { - self.nodes[16] = self.trie.trans(self.nodes[16]) - return self.nodes[16] -} -func (self *FullNode) Branches() []Node { - return self.nodes[:16] -} - -func (self *FullNode) Copy(t *Trie) Node { - nnode := NewFullNode(t) - for i, node := range self.nodes { - if node != nil { - nnode.nodes[i] = node - } - } - nnode.dirty = true - - return nnode -} - -// Returns the length of non-nil nodes -func (self *FullNode) Len() (amount int) { - for _, node := range self.nodes { - if node != nil { - amount++ - } - } - - return -} - -func (self *FullNode) Hash() interface{} { - return self.trie.store(self) -} - -func (self *FullNode) RlpData() interface{} { - t := make([]interface{}, 17) - for i, node := range self.nodes { - if node != nil { - t[i] = node.Hash() - } else { - t[i] = "" - } - } - - return t -} - -func (self *FullNode) set(k byte, value Node) { - self.nodes[int(k)] = value - self.dirty = true -} - -func (self *FullNode) branch(i byte) Node { - if self.nodes[int(i)] != nil { - self.nodes[int(i)] = self.trie.trans(self.nodes[int(i)]) - - return self.nodes[int(i)] - } - return nil -} - -func (self *FullNode) setDirty(dirty bool) { - self.dirty = dirty -} diff --git a/trie/hashnode.go b/trie/hashnode.go deleted file mode 100644 index 53071f353f..0000000000 --- a/trie/hashnode.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2014 The go-ethereum Authors && Copyright 2015 go-expanse Authors -// This file is part of the go-expanse library. -// -// The go-expanse library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-expanse library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-expanse library. If not, see . - -package trie - -import "github.com/expanse-project/go-expanse/common" - -type HashNode struct { - key []byte - trie *Trie - dirty bool -} - -func NewHash(key []byte, trie *Trie) *HashNode { - return &HashNode{key, trie, false} -} - -func (self *HashNode) RlpData() interface{} { - return self.key -} - -func (self *HashNode) Hash() interface{} { - return self.key -} - -func (self *HashNode) setDirty(dirty bool) { - self.dirty = dirty -} - -// 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(common.CopyBytes(self.key), t) } diff --git a/trie/shortnode.go b/trie/shortnode.go deleted file mode 100644 index 30b9467871..0000000000 --- a/trie/shortnode.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2014 The go-ethereum Authors && Copyright 2015 go-expanse Authors -// This file is part of the go-expanse library. -// -// The go-expanse library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-expanse library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-expanse library. If not, see . - -package trie - -import "github.com/expanse-project/go-expanse/common" - -type ShortNode struct { - trie *Trie - key []byte - value Node - dirty bool -} - -func NewShortNode(t *Trie, key []byte, value Node) *ShortNode { - return &ShortNode{t, CompactEncode(key), value, false} -} -func (self *ShortNode) Value() Node { - self.value = self.trie.trans(self.value) - - return self.value -} -func (self *ShortNode) Dirty() bool { return self.dirty } -func (self *ShortNode) Copy(t *Trie) Node { - node := &ShortNode{t, nil, self.value.Copy(t), self.dirty} - node.key = common.CopyBytes(self.key) - node.dirty = true - return node -} - -func (self *ShortNode) RlpData() interface{} { - return []interface{}{self.key, self.value.Hash()} -} -func (self *ShortNode) Hash() interface{} { - return self.trie.store(self) -} - -func (self *ShortNode) Key() []byte { - return CompactDecode(self.key) -} - -func (self *ShortNode) setDirty(dirty bool) { - self.dirty = dirty -} diff --git a/trie/valuenode.go b/trie/valuenode.go deleted file mode 100644 index 92a715b430..0000000000 --- a/trie/valuenode.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2014 The go-ethereum Authors && Copyright 2015 go-expanse Authors -// This file is part of the go-expanse library. -// -// The go-expanse library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-expanse library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-expanse library. If not, see . - -package trie - -import "github.com/expanse-project/go-expanse/common" - -type ValueNode struct { - trie *Trie - data []byte - dirty bool -} - -func NewValueNode(trie *Trie, data []byte) *ValueNode { - return &ValueNode{trie, data, false} -} - -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 self.dirty } -func (self *ValueNode) Copy(t *Trie) Node { - return &ValueNode{t, common.CopyBytes(self.data), self.dirty} -} -func (self *ValueNode) RlpData() interface{} { return self.data } -func (self *ValueNode) Hash() interface{} { return self.data } - -func (self *ValueNode) setDirty(dirty bool) { - self.dirty = dirty -}