aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2014-07-21 20:26:29 +0800
committerzelig <viktor.tron@gmail.com>2014-07-21 20:26:29 +0800
commit1e4af85a380977233a3bceaf5e2a020a281aa19a (patch)
treeacf6f1506952e9edc400d3b450d153db90ce536e /ethutil
parent017d36e6b2e127084448dfb38bd1b8de7424e1c9 (diff)
parent2762ec22d0693b406ead2f0c07b62e9b66d395e4 (diff)
downloaddexon-1e4af85a380977233a3bceaf5e2a020a281aa19a.tar.gz
dexon-1e4af85a380977233a3bceaf5e2a020a281aa19a.tar.zst
dexon-1e4af85a380977233a3bceaf5e2a020a281aa19a.zip
merge upstream
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/bytes.go16
-rw-r--r--ethutil/config.go1
-rw-r--r--ethutil/value.go21
3 files changed, 32 insertions, 6 deletions
diff --git a/ethutil/bytes.go b/ethutil/bytes.go
index d68a69433..34fff7d42 100644
--- a/ethutil/bytes.go
+++ b/ethutil/bytes.go
@@ -118,7 +118,7 @@ func FormatData(data string) []byte {
// Simple stupid
d := new(big.Int)
if data[0:1] == "\"" && data[len(data)-1:] == "\"" {
- return RightPadBytes([]byte(data), 32)
+ return RightPadBytes([]byte(data[1:len(data)-1]), 32)
} else if len(data) > 1 && data[:2] == "0x" {
d.SetBytes(Hex2Bytes(data[2:]))
} else {
@@ -149,3 +149,17 @@ func LeftPadBytes(slice []byte, l int) []byte {
return padded
}
+
+func Address(slice []byte) (addr []byte) {
+ if len(slice) < 20 {
+ addr = LeftPadBytes(slice, 20)
+ } else if len(slice) > 20 {
+ addr = slice[len(slice)-20:]
+ } else {
+ addr = slice
+ }
+
+ addr = CopyBytes(addr)
+
+ return
+}
diff --git a/ethutil/config.go b/ethutil/config.go
index 2f3d706fe..41bece21d 100644
--- a/ethutil/config.go
+++ b/ethutil/config.go
@@ -14,6 +14,7 @@ type ConfigManager struct {
ExecPath string
Debug bool
Diff bool
+ DiffType string
Paranoia bool
conf *globalconf.GlobalConf
diff --git a/ethutil/value.go b/ethutil/value.go
index b37b33c28..fba7426d1 100644
--- a/ethutil/value.go
+++ b/ethutil/value.go
@@ -40,13 +40,9 @@ func (val *Value) Len() int {
//return val.kind.Len()
if data, ok := val.Val.([]interface{}); ok {
return len(data)
- } else if data, ok := val.Val.([]byte); ok {
- return len(data)
- } else if data, ok := val.Val.(string); ok {
- return len(data)
}
- return 0
+ return len(val.Bytes())
}
func (val *Value) Raw() interface{} {
@@ -118,6 +114,8 @@ func (val *Value) Bytes() []byte {
return []byte{s}
} else if s, ok := val.Val.(string); ok {
return []byte(s)
+ } else if s, ok := val.Val.(*big.Int); ok {
+ return s.Bytes()
}
return []byte{}
@@ -190,6 +188,19 @@ func (val *Value) Get(idx int) *Value {
return NewValue(nil)
}
+func (self *Value) Copy() *Value {
+ switch val := self.Val.(type) {
+ case *big.Int:
+ return NewValue(new(big.Int).Set(val))
+ case []byte:
+ return NewValue(CopyBytes(val))
+ default:
+ return NewValue(self.Val)
+ }
+
+ return nil
+}
+
func (val *Value) Cmp(o *Value) bool {
return reflect.DeepEqual(val.Val, o.Val)
}