aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-09-15 21:42:12 +0800
committerobscuren <geffobscura@gmail.com>2014-09-15 21:42:12 +0800
commit33a0dec8a157b9687ca6038f4deb011f3f1f7bdc (patch)
tree197b792e06dc3952df93957a39fdf6e44582ac96 /ethutil
parent2f614900e82036e3e8f6f6a714efc43e09aca830 (diff)
downloaddexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.tar.gz
dexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.tar.zst
dexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.zip
Improved catching up and refactored
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/bytes.go16
-rw-r--r--ethutil/rlp.go2
-rw-r--r--ethutil/set.go16
3 files changed, 28 insertions, 6 deletions
diff --git a/ethutil/bytes.go b/ethutil/bytes.go
index e38f89454..f151d16ee 100644
--- a/ethutil/bytes.go
+++ b/ethutil/bytes.go
@@ -9,6 +9,22 @@ import (
"strings"
)
+type Bytes []byte
+
+func (self Bytes) String() string {
+ return string(self)
+}
+
+func DeleteFromByteSlice(s [][]byte, hash []byte) [][]byte {
+ for i, h := range s {
+ if bytes.Compare(h, hash) == 0 {
+ return append(s[:i], s[i+1:]...)
+ }
+ }
+
+ return s
+}
+
// Number to bytes
//
// Returns the number in bytes with the specified base
diff --git a/ethutil/rlp.go b/ethutil/rlp.go
index 17ff627eb..febfb78e1 100644
--- a/ethutil/rlp.go
+++ b/ethutil/rlp.go
@@ -124,6 +124,8 @@ func Encode(object interface{}) []byte {
} else {
buff.Write(Encode(t.Bytes()))
}
+ case Bytes:
+ buff.Write(Encode([]byte(t)))
case []byte:
if len(t) == 1 && t[0] <= 0x7f {
buff.Write(t)
diff --git a/ethutil/set.go b/ethutil/set.go
index 80e2edde2..7955edac0 100644
--- a/ethutil/set.go
+++ b/ethutil/set.go
@@ -4,9 +4,13 @@ type Settable interface {
AsSet() UniqueSet
}
-type UniqueSet map[interface{}]struct{}
+type Stringable interface {
+ String() string
+}
+
+type UniqueSet map[string]struct{}
-func NewSet(v ...interface{}) UniqueSet {
+func NewSet(v ...Stringable) UniqueSet {
set := make(UniqueSet)
for _, val := range v {
set.Insert(val)
@@ -15,14 +19,14 @@ func NewSet(v ...interface{}) UniqueSet {
return set
}
-func (self UniqueSet) Insert(k interface{}) UniqueSet {
- self[k] = struct{}{}
+func (self UniqueSet) Insert(k Stringable) UniqueSet {
+ self[k.String()] = struct{}{}
return self
}
-func (self UniqueSet) Include(k interface{}) bool {
- _, ok := self[k]
+func (self UniqueSet) Include(k Stringable) bool {
+ _, ok := self[k.String()]
return ok
}