aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/config.go2
-rw-r--r--ethutil/encoding.go3
-rw-r--r--ethutil/helpers.go4
-rw-r--r--ethutil/rlp.go8
-rw-r--r--ethutil/trie.go9
-rw-r--r--ethutil/value.go2
6 files changed, 15 insertions, 13 deletions
diff --git a/ethutil/config.go b/ethutil/config.go
index b361a3079..e3b5f0275 100644
--- a/ethutil/config.go
+++ b/ethutil/config.go
@@ -43,7 +43,7 @@ func ReadConfig(base string) *config {
}
}
- Config = &config{ExecPath: path, Debug: true, Ver: "0.2.2"}
+ Config = &config{ExecPath: path, Debug: true, Ver: "0.2.3"}
Config.Log = NewLogger(LogFile|LogStd, 0)
}
diff --git a/ethutil/encoding.go b/ethutil/encoding.go
index 207548c93..1f661947a 100644
--- a/ethutil/encoding.go
+++ b/ethutil/encoding.go
@@ -3,7 +3,6 @@ package ethutil
import (
"bytes"
"encoding/hex"
- _ "fmt"
"strings"
)
@@ -36,7 +35,7 @@ func CompactEncode(hexSlice []int) string {
func CompactDecode(str string) []int {
base := CompactHexDecode(str)
base = base[:len(base)-1]
- if base[0] >= 2 { // && base[len(base)-1] != 16 {
+ if base[0] >= 2 {
base = append(base, 16)
}
if base[0]%2 == 1 {
diff --git a/ethutil/helpers.go b/ethutil/helpers.go
index 2e3aeb9a3..aa0f79a04 100644
--- a/ethutil/helpers.go
+++ b/ethutil/helpers.go
@@ -58,3 +58,7 @@ func MatchingNibbleLength(a, b []int) int {
func Hex(d []byte) string {
return hex.EncodeToString(d)
}
+func FromHex(str string) []byte {
+ h, _ := hex.DecodeString(str)
+ return h
+}
diff --git a/ethutil/rlp.go b/ethutil/rlp.go
index 025d269a0..e633f5f1d 100644
--- a/ethutil/rlp.go
+++ b/ethutil/rlp.go
@@ -86,13 +86,6 @@ func DecodeWithReader(reader *bytes.Buffer) interface{} {
// TODO Use a bytes.Buffer instead of a raw byte slice.
// Cleaner code, and use draining instead of seeking the next bytes to read
func Decode(data []byte, pos uint64) (interface{}, uint64) {
- /*
- if pos > uint64(len(data)-1) {
- log.Println(data)
- log.Panicf("index out of range %d for data %q, l = %d", pos, data, len(data))
- }
- */
-
var slice []interface{}
char := int(data[pos])
switch {
@@ -131,7 +124,6 @@ func Decode(data []byte, pos uint64) (interface{}, uint64) {
case char <= 0xff:
l := uint64(data[pos]) - 0xf7
- //b := BigD(data[pos+1 : pos+1+l]).Uint64()
b := ReadVarint(bytes.NewReader(data[pos+1 : pos+1+l]))
pos = pos + l + 1
diff --git a/ethutil/trie.go b/ethutil/trie.go
index 7140a1b36..95abca602 100644
--- a/ethutil/trie.go
+++ b/ethutil/trie.go
@@ -98,22 +98,25 @@ func (cache *Cache) Undo() {
// Please note that the data isn't persisted unless `Sync` is
// explicitly called.
type Trie struct {
- Root interface{}
+ prevRoot interface{}
+ Root interface{}
//db Database
cache *Cache
}
func NewTrie(db Database, Root interface{}) *Trie {
- return &Trie{cache: NewCache(db), Root: Root}
+ return &Trie{cache: NewCache(db), Root: Root, prevRoot: Root}
}
// Save the cached value to the database.
func (t *Trie) Sync() {
t.cache.Commit()
+ t.prevRoot = t.Root
}
func (t *Trie) Undo() {
t.cache.Undo()
+ t.Root = t.prevRoot
}
/*
@@ -181,6 +184,7 @@ func (t *Trie) GetNode(node interface{}) *Value {
}
func (t *Trie) UpdateState(node interface{}, key []int, value string) interface{} {
+
if value != "" {
return t.InsertState(node, key, value)
} else {
@@ -241,6 +245,7 @@ func (t *Trie) InsertState(node interface{}, key []int, value interface{}) inter
// Check for "special" 2 slice type node
if currentNode.Len() == 2 {
// Decode the key
+
k := CompactDecode(currentNode.Get(0).Str())
v := currentNode.Get(1).Raw()
diff --git a/ethutil/value.go b/ethutil/value.go
index 701ece5bb..d3a38f87f 100644
--- a/ethutil/value.go
+++ b/ethutil/value.go
@@ -98,6 +98,8 @@ func (val *Value) Str() string {
return string(a)
} else if a, ok := val.Val.(string); ok {
return a
+ } else if a, ok := val.Val.(byte); ok {
+ return string(a)
}
return ""