Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
707d4137
Commit
707d4137
authored
Jun 29, 2014
by
zelig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor ethutil/trie to ethtrie
parent
4be35217
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
30 deletions
+33
-30
state.go
ethchain/state.go
+3
-2
encoding.go
ethtrie/encoding.go
+1
-1
encoding_test.go
ethtrie/encoding_test.go
+1
-1
slice.go
ethtrie/slice.go
+1
-1
trie.go
ethtrie/trie.go
+26
-24
trie_test.go
ethtrie/trie_test.go
+1
-1
No files found.
ethchain/state.go
View file @
707d4137
package
ethchain
import
(
"github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil"
"math/big"
)
...
...
@@ -12,7 +13,7 @@ import (
// * Accounts
type
State
struct
{
// The trie for this structure
trie
*
eth
util
.
Trie
trie
*
eth
trie
.
Trie
stateObjects
map
[
string
]
*
StateObject
...
...
@@ -20,7 +21,7 @@ type State struct {
}
// Create a new state from a given trie
func
NewState
(
trie
*
eth
util
.
Trie
)
*
State
{
func
NewState
(
trie
*
eth
trie
.
Trie
)
*
State
{
return
&
State
{
trie
:
trie
,
stateObjects
:
make
(
map
[
string
]
*
StateObject
),
manifest
:
NewManifest
()}
}
...
...
eth
util
/encoding.go
→
eth
trie
/encoding.go
View file @
707d4137
package
eth
util
package
eth
trie
import
(
"bytes"
...
...
eth
util
/encoding_test.go
→
eth
trie
/encoding_test.go
View file @
707d4137
package
eth
util
package
eth
trie
import
(
"fmt"
...
...
eth
util
/slice.go
→
eth
trie
/slice.go
View file @
707d4137
package
eth
util
package
eth
trie
import
()
...
...
eth
util
/trie.go
→
eth
trie
/trie.go
View file @
707d4137
package
eth
util
package
eth
trie
import
(
"fmt"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethutil"
"reflect"
"sync"
)
...
...
@@ -21,11 +23,11 @@ type StateObject interface {
type
Node
struct
{
Key
[]
byte
Value
*
Value
Value
*
ethutil
.
Value
Dirty
bool
}
func
NewNode
(
key
[]
byte
,
val
*
Value
,
dirty
bool
)
*
Node
{
func
NewNode
(
key
[]
byte
,
val
*
ethutil
.
Value
,
dirty
bool
)
*
Node
{
return
&
Node
{
Key
:
key
,
Value
:
val
,
Dirty
:
dirty
}
}
...
...
@@ -35,20 +37,20 @@ func (n *Node) Copy() *Node {
type
Cache
struct
{
nodes
map
[
string
]
*
Node
db
Database
db
ethutil
.
Database
IsDirty
bool
}
func
NewCache
(
db
Database
)
*
Cache
{
func
NewCache
(
db
ethutil
.
Database
)
*
Cache
{
return
&
Cache
{
db
:
db
,
nodes
:
make
(
map
[
string
]
*
Node
)}
}
func
(
cache
*
Cache
)
Put
(
v
interface
{})
interface
{}
{
value
:=
NewValue
(
v
)
value
:=
ethutil
.
NewValue
(
v
)
enc
:=
value
.
Encode
()
if
len
(
enc
)
>=
32
{
sha
:=
Sha3Bin
(
enc
)
sha
:=
ethcrypto
.
Sha3Bin
(
enc
)
cache
.
nodes
[
string
(
sha
)]
=
NewNode
(
sha
,
value
,
true
)
cache
.
IsDirty
=
true
...
...
@@ -59,7 +61,7 @@ func (cache *Cache) Put(v interface{}) interface{} {
return
v
}
func
(
cache
*
Cache
)
Get
(
key
[]
byte
)
*
Value
{
func
(
cache
*
Cache
)
Get
(
key
[]
byte
)
*
ethutil
.
Value
{
// First check if the key is the cache
if
cache
.
nodes
[
string
(
key
)]
!=
nil
{
return
cache
.
nodes
[
string
(
key
)]
.
Value
...
...
@@ -68,7 +70,7 @@ func (cache *Cache) Get(key []byte) *Value {
// Get the key of the database instead and cache it
data
,
_
:=
cache
.
db
.
Get
(
key
)
// Create the cached value
value
:=
NewValueFromBytes
(
data
)
value
:=
ethutil
.
NewValueFromBytes
(
data
)
// Create caching node
cache
.
nodes
[
string
(
key
)]
=
NewNode
(
key
,
value
,
false
)
...
...
@@ -128,7 +130,7 @@ type Trie struct {
func
copyRoot
(
root
interface
{})
interface
{}
{
var
prevRootCopy
interface
{}
if
b
,
ok
:=
root
.
([]
byte
);
ok
{
prevRootCopy
=
CopyBytes
(
b
)
prevRootCopy
=
ethutil
.
CopyBytes
(
b
)
}
else
{
prevRootCopy
=
root
}
...
...
@@ -136,7 +138,7 @@ func copyRoot(root interface{}) interface{} {
return
prevRootCopy
}
func
NewTrie
(
db
Database
,
Root
interface
{})
*
Trie
{
func
NewTrie
(
db
ethutil
.
Database
,
Root
interface
{})
*
Trie
{
// Make absolute sure the root is copied
r
:=
copyRoot
(
Root
)
p
:=
copyRoot
(
Root
)
...
...
@@ -176,7 +178,7 @@ func (t *Trie) Get(key string) string {
defer
t
.
mut
.
RUnlock
()
k
:=
CompactHexDecode
(
key
)
c
:=
NewValue
(
t
.
GetState
(
t
.
Root
,
k
))
c
:=
ethutil
.
NewValue
(
t
.
GetState
(
t
.
Root
,
k
))
return
c
.
Str
()
}
...
...
@@ -186,7 +188,7 @@ func (t *Trie) Delete(key string) {
}
func
(
t
*
Trie
)
GetState
(
node
interface
{},
key
[]
int
)
interface
{}
{
n
:=
NewValue
(
node
)
n
:=
ethutil
.
NewValue
(
node
)
// Return the node if key is empty (= found)
if
len
(
key
)
==
0
||
n
.
IsNil
()
||
n
.
Len
()
==
0
{
return
node
...
...
@@ -216,8 +218,8 @@ func (t *Trie) GetState(node interface{}, key []int) interface{} {
return
""
}
func
(
t
*
Trie
)
GetNode
(
node
interface
{})
*
Value
{
n
:=
NewValue
(
node
)
func
(
t
*
Trie
)
GetNode
(
node
interface
{})
*
ethutil
.
Value
{
n
:=
ethutil
.
NewValue
(
node
)
if
!
n
.
Get
(
0
)
.
IsNil
()
{
return
n
...
...
@@ -227,7 +229,7 @@ func (t *Trie) GetNode(node interface{}) *Value {
if
len
(
str
)
==
0
{
return
n
}
else
if
len
(
str
)
<
32
{
return
NewValueFromBytes
([]
byte
(
str
))
return
ethutil
.
NewValueFromBytes
([]
byte
(
str
))
}
return
t
.
cache
.
Get
(
n
.
Bytes
())
...
...
@@ -273,7 +275,7 @@ func (t *Trie) InsertState(node interface{}, key []int, value interface{}) inter
}
// New node
n
:=
NewValue
(
node
)
n
:=
ethutil
.
NewValue
(
node
)
if
node
==
nil
||
(
n
.
Type
()
==
reflect
.
String
&&
(
n
.
Str
()
==
""
||
n
.
Get
(
0
)
.
IsNil
()))
||
n
.
Len
()
==
0
{
newNode
:=
[]
interface
{}{
CompactEncode
(
key
),
value
}
...
...
@@ -345,7 +347,7 @@ func (t *Trie) DeleteState(node interface{}, key []int) interface{} {
}
// New node
n
:=
NewValue
(
node
)
n
:=
ethutil
.
NewValue
(
node
)
if
node
==
nil
||
(
n
.
Type
()
==
reflect
.
String
&&
(
n
.
Str
()
==
""
||
n
.
Get
(
0
)
.
IsNil
()))
||
n
.
Len
()
==
0
{
return
""
}
...
...
@@ -422,7 +424,7 @@ func (t *Trie) DeleteState(node interface{}, key []int) interface{} {
// Simple compare function which creates a rlp value out of the evaluated objects
func
(
t
*
Trie
)
Cmp
(
trie
*
Trie
)
bool
{
return
NewValue
(
t
.
Root
)
.
Cmp
(
NewValue
(
trie
.
Root
))
return
ethutil
.
NewValue
(
t
.
Root
)
.
Cmp
(
ethutil
.
NewValue
(
trie
.
Root
))
}
// Returns a copy of this trie
...
...
@@ -452,7 +454,7 @@ func (t *Trie) NewIterator() *TrieIterator {
// Some time in the near future this will need refactoring :-)
// XXX Note to self, IsSlice == inline node. Str == sha3 to node
func
(
it
*
TrieIterator
)
workNode
(
currentNode
*
Value
)
{
func
(
it
*
TrieIterator
)
workNode
(
currentNode
*
ethutil
.
Value
)
{
if
currentNode
.
Len
()
==
2
{
k
:=
CompactDecode
(
currentNode
.
Get
(
0
)
.
Str
())
...
...
@@ -495,7 +497,7 @@ func (it *TrieIterator) Collect() [][]byte {
return
nil
}
it
.
getNode
(
NewValue
(
it
.
trie
.
Root
)
.
Bytes
())
it
.
getNode
(
ethutil
.
NewValue
(
it
.
trie
.
Root
)
.
Bytes
())
return
it
.
shas
}
...
...
@@ -516,17 +518,17 @@ func (it *TrieIterator) Value() string {
return
""
}
type
EachCallback
func
(
key
string
,
node
*
Value
)
type
EachCallback
func
(
key
string
,
node
*
ethutil
.
Value
)
func
(
it
*
TrieIterator
)
Each
(
cb
EachCallback
)
{
it
.
fetchNode
(
nil
,
NewValue
(
it
.
trie
.
Root
)
.
Bytes
(),
cb
)
it
.
fetchNode
(
nil
,
ethutil
.
NewValue
(
it
.
trie
.
Root
)
.
Bytes
(),
cb
)
}
func
(
it
*
TrieIterator
)
fetchNode
(
key
[]
int
,
node
[]
byte
,
cb
EachCallback
)
{
it
.
iterateNode
(
key
,
it
.
trie
.
cache
.
Get
(
node
),
cb
)
}
func
(
it
*
TrieIterator
)
iterateNode
(
key
[]
int
,
currentNode
*
Value
,
cb
EachCallback
)
{
func
(
it
*
TrieIterator
)
iterateNode
(
key
[]
int
,
currentNode
*
ethutil
.
Value
,
cb
EachCallback
)
{
if
currentNode
.
Len
()
==
2
{
k
:=
CompactDecode
(
currentNode
.
Get
(
0
)
.
Str
())
...
...
eth
util
/trie_test.go
→
eth
trie
/trie_test.go
View file @
707d4137
package
eth
util
package
eth
trie
import
(
"fmt"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment