aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-09-13 19:14:24 +0800
committerobscuren <geffobscura@gmail.com>2014-09-13 19:14:24 +0800
commit10564723b9ffa14904907a0ebc984fa25e4f1eab (patch)
treeb979ba28f8d81378fbebe73b90ba95d48a0cd5cd
parentc0187930dc352c645c223e17364623a68413cb74 (diff)
downloaddexon-10564723b9ffa14904907a0ebc984fa25e4f1eab.tar.gz
dexon-10564723b9ffa14904907a0ebc984fa25e4f1eab.tar.zst
dexon-10564723b9ffa14904907a0ebc984fa25e4f1eab.zip
added string casting
-rw-r--r--ethutil/value.go10
-rw-r--r--ethutil/value_test.go6
2 files changed, 12 insertions, 4 deletions
diff --git a/ethutil/value.go b/ethutil/value.go
index b336345ca..e8148b990 100644
--- a/ethutil/value.go
+++ b/ethutil/value.go
@@ -1,9 +1,11 @@
package ethutil
import (
+ "bytes"
"fmt"
"math/big"
"reflect"
+ "strconv"
)
// Data values are returned by the rlp decoder. The data values represents
@@ -93,6 +95,9 @@ func (val *Value) Int() int64 {
return new(big.Int).SetBytes(Val).Int64()
} else if Val, ok := val.Val.(*big.Int); ok {
return Val.Int64()
+ } else if Val, ok := val.Val.(string); ok {
+ n, _ := strconv.Atoi(Val)
+ return int64(n)
}
return 0
@@ -246,10 +251,7 @@ func (val *Value) Cmp(o *Value) bool {
}
func (self *Value) DeepCmp(o *Value) bool {
- a := NewValue(self.BigInt())
- b := NewValue(o.BigInt())
-
- return a.Cmp(b)
+ return bytes.Compare(self.Bytes(), o.Bytes()) == 0
}
func (val *Value) Encode() []byte {
diff --git a/ethutil/value_test.go b/ethutil/value_test.go
index 710cbd887..5452a0790 100644
--- a/ethutil/value_test.go
+++ b/ethutil/value_test.go
@@ -2,6 +2,7 @@ package ethutil
import (
"bytes"
+ "fmt"
"math/big"
"testing"
)
@@ -78,3 +79,8 @@ func TestMath(t *testing.T) {
t.Error("Expected 0, got", a)
}
}
+
+func TestString(t *testing.T) {
+ a := NewValue("10")
+ fmt.Println("VALUE WITH STRING:", a.Int())
+}