Trie fixes

This commit is contained in:
obscuren
2014-07-17 11:21:18 +02:00
parent 14c4f06100
commit ed3424ff75
8 changed files with 129 additions and 38 deletions

View File

@ -150,12 +150,16 @@ func LeftPadBytes(slice []byte, l int) []byte {
return padded
}
func Address(slice []byte) []byte {
func Address(slice []byte) (addr []byte) {
if len(slice) < 20 {
slice = LeftPadBytes(slice, 20)
addr = LeftPadBytes(slice, 20)
} else if len(slice) > 20 {
slice = slice[len(slice)-20:]
addr = slice[len(slice)-20:]
} else {
addr = slice
}
return slice
addr = CopyBytes(addr)
return
}

View File

@ -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{}