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
58d477f7
Commit
58d477f7
authored
Dec 24, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed a bug where keys where serialised twice
parent
804af965
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
12 deletions
+23
-12
fullnode.go
ptrie/fullnode.go
+3
-2
iterator.go
ptrie/iterator.go
+1
-1
node.go
ptrie/node.go
+2
-2
trie.go
ptrie/trie.go
+17
-7
No files found.
ptrie/fullnode.go
View file @
58d477f7
...
...
@@ -23,7 +23,9 @@ func (self *FullNode) Branches() []Node {
func
(
self
*
FullNode
)
Copy
()
Node
{
nnode
:=
NewFullNode
(
self
.
trie
)
for
i
,
node
:=
range
self
.
nodes
{
nnode
.
nodes
[
i
]
=
node
if
node
!=
nil
{
nnode
.
nodes
[
i
]
=
node
}
}
return
nnode
...
...
@@ -60,7 +62,6 @@ func (self *FullNode) RlpData() interface{} {
func
(
self
*
FullNode
)
set
(
k
byte
,
value
Node
)
{
if
_
,
ok
:=
value
.
(
*
ValueNode
);
ok
&&
k
!=
16
{
fmt
.
Println
(
value
,
k
)
panic
(
":("
)
}
self
.
nodes
[
int
(
k
)]
=
value
...
...
ptrie/iterator.go
View file @
58d477f7
...
...
@@ -14,7 +14,7 @@ type Iterator struct {
}
func
NewIterator
(
trie
*
Trie
)
*
Iterator
{
return
&
Iterator
{
trie
:
trie
,
Key
:
[]
byte
{
0
}
}
return
&
Iterator
{
trie
:
trie
,
Key
:
make
([]
byte
,
32
)
}
}
func
(
self
*
Iterator
)
Next
()
bool
{
...
...
ptrie/node.go
View file @
58d477f7
...
...
@@ -17,7 +17,7 @@ type Node interface {
func
(
self
*
ValueNode
)
String
()
string
{
return
self
.
fstring
(
""
)
}
func
(
self
*
FullNode
)
String
()
string
{
return
self
.
fstring
(
""
)
}
func
(
self
*
ShortNode
)
String
()
string
{
return
self
.
fstring
(
""
)
}
func
(
self
*
ValueNode
)
fstring
(
ind
string
)
string
{
return
fmt
.
Sprintf
(
"%
s
"
,
self
.
data
)
}
func
(
self
*
ValueNode
)
fstring
(
ind
string
)
string
{
return
fmt
.
Sprintf
(
"%
x
"
,
self
.
data
)
}
func
(
self
*
HashNode
)
fstring
(
ind
string
)
string
{
return
fmt
.
Sprintf
(
"%x "
,
self
.
key
)
}
// Full node
...
...
@@ -36,5 +36,5 @@ func (self *FullNode) fstring(ind string) string {
// Short node
func
(
self
*
ShortNode
)
fstring
(
ind
string
)
string
{
return
fmt
.
Sprintf
(
"[ %
s
: %v ] "
,
self
.
key
,
self
.
value
.
fstring
(
ind
+
" "
))
return
fmt
.
Sprintf
(
"[ %
x
: %v ] "
,
self
.
key
,
self
.
value
.
fstring
(
ind
+
" "
))
}
ptrie/trie.go
View file @
58d477f7
...
...
@@ -215,7 +215,7 @@ func (self *Trie) get(node Node, key []byte) Node {
}
func
(
self
*
Trie
)
delete
(
node
Node
,
key
[]
byte
)
Node
{
if
len
(
key
)
==
0
{
if
len
(
key
)
==
0
&&
node
==
nil
{
return
nil
}
...
...
@@ -234,7 +234,9 @@ func (self *Trie) delete(node Node, key []byte) Node {
nkey
:=
append
(
k
,
child
.
Key
()
...
)
n
=
NewShortNode
(
self
,
nkey
,
child
.
Value
())
case
*
FullNode
:
n
=
NewShortNode
(
self
,
node
.
key
,
child
)
sn
:=
NewShortNode
(
self
,
node
.
Key
(),
child
)
sn
.
key
=
node
.
key
n
=
sn
}
return
n
...
...
@@ -275,9 +277,10 @@ func (self *Trie) delete(node Node, key []byte) Node {
}
return
nnode
case
nil
:
return
nil
default
:
panic
(
"Invalid node"
)
panic
(
fmt
.
Sprintf
(
"%T: invalid node: %v (%v)"
,
node
,
node
,
key
)
)
}
}
...
...
@@ -288,7 +291,10 @@ func (self *Trie) mknode(value *ethutil.Value) Node {
case
0
:
return
nil
case
2
:
return
NewShortNode
(
self
,
trie
.
CompactDecode
(
string
(
value
.
Get
(
0
)
.
Bytes
())),
self
.
mknode
(
value
.
Get
(
1
)))
// A value node may consists of 2 bytes.
if
value
.
Get
(
0
)
.
Len
()
!=
0
{
return
NewShortNode
(
self
,
trie
.
CompactDecode
(
string
(
value
.
Get
(
0
)
.
Bytes
())),
self
.
mknode
(
value
.
Get
(
1
)))
}
case
17
:
fnode
:=
NewFullNode
(
self
)
for
i
:=
0
;
i
<
l
;
i
++
{
...
...
@@ -297,9 +303,9 @@ func (self *Trie) mknode(value *ethutil.Value) Node {
return
fnode
case
32
:
return
&
HashNode
{
value
.
Bytes
()}
default
:
return
&
ValueNode
{
self
,
value
.
Bytes
()}
}
return
&
ValueNode
{
self
,
value
.
Bytes
()}
}
func
(
self
*
Trie
)
trans
(
node
Node
)
Node
{
...
...
@@ -323,3 +329,7 @@ func (self *Trie) store(node Node) interface{} {
return
node
.
RlpData
()
}
func
(
self
*
Trie
)
PrintRoot
()
{
fmt
.
Println
(
self
.
root
)
}
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