diff options
Diffstat (limited to 'ethutil')
-rw-r--r-- | ethutil/bytes.go | 16 | ||||
-rw-r--r-- | ethutil/config.go | 1 | ||||
-rw-r--r-- | ethutil/value.go | 21 |
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) } |