accounts/abi: Improve naming of element size func

The full step size for unpacking an array
 is now retrieved with "getFullElemSize".
This commit is contained in:
protolambda 2018-01-06 13:45:18 +01:00
parent cc3a8271d1
commit 8929a3b239
No known key found for this signature in database
GPG key ID: EC89FDBB2B4C7623

View file

@ -93,13 +93,13 @@ func readFixedBytes(t Type, word []byte) (interface{}, error) {
}
func getDeepSizeForType(t *Type) int {
func getFullElemSize(elem *Type) int {
//all other should be counted as 32 (slices have pointers to respective elements)
size := 32
//arrays wrap it, each element being the same size
for t.T == ArrayTy {
size *= t.Size
t = t.Elem
for elem.T == ArrayTy {
size *= elem.Size
elem = elem.Elem
}
return size
}
@ -126,9 +126,11 @@ func forEachUnpack(t Type, output []byte, start, size int) (interface{}, error)
return nil, fmt.Errorf("abi: invalid type in array/slice unpacking stage")
}
// Arrays have packed elements, resulting in longer unpack steps.
// Slices have just 32 bytes per element (pointing to the contents).
elemSize := 32
if t.T == ArrayTy {
elemSize = getDeepSizeForType(t.Elem)
elemSize = getFullElemSize(t.Elem)
}
for i, j := start, 0; j < size; i, j = i+elemSize, j+1 {