added string casting
This commit is contained in:
parent
c0187930dc
commit
10564723b9
|
@ -1,9 +1,11 @@
|
||||||
package ethutil
|
package ethutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Data values are returned by the rlp decoder. The data values represents
|
// 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()
|
return new(big.Int).SetBytes(Val).Int64()
|
||||||
} else if Val, ok := val.Val.(*big.Int); ok {
|
} else if Val, ok := val.Val.(*big.Int); ok {
|
||||||
return Val.Int64()
|
return Val.Int64()
|
||||||
|
} else if Val, ok := val.Val.(string); ok {
|
||||||
|
n, _ := strconv.Atoi(Val)
|
||||||
|
return int64(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
@ -246,10 +251,7 @@ func (val *Value) Cmp(o *Value) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Value) DeepCmp(o *Value) bool {
|
func (self *Value) DeepCmp(o *Value) bool {
|
||||||
a := NewValue(self.BigInt())
|
return bytes.Compare(self.Bytes(), o.Bytes()) == 0
|
||||||
b := NewValue(o.BigInt())
|
|
||||||
|
|
||||||
return a.Cmp(b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (val *Value) Encode() []byte {
|
func (val *Value) Encode() []byte {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ethutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -78,3 +79,8 @@ func TestMath(t *testing.T) {
|
||||||
t.Error("Expected 0, got", a)
|
t.Error("Expected 0, got", a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestString(t *testing.T) {
|
||||||
|
a := NewValue("10")
|
||||||
|
fmt.Println("VALUE WITH STRING:", a.Int())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue