merge upstream
This commit is contained in:
@ -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
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ type ConfigManager struct {
|
||||
ExecPath string
|
||||
Debug bool
|
||||
Diff bool
|
||||
DiffType string
|
||||
Paranoia bool
|
||||
|
||||
conf *globalconf.GlobalConf
|
||||
|
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user