From da590e60ee3467f72a3b3c2983de9ea01134115d Mon Sep 17 00:00:00 2001 From: vedhavyas Date: Mon, 26 Nov 2018 13:35:53 +0100 Subject: [PATCH] review chnages --- accounts/abi/argument.go | 2 +- accounts/abi/type.go | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/accounts/abi/argument.go b/accounts/abi/argument.go index b5e6cd1858..c69516f128 100644 --- a/accounts/abi/argument.go +++ b/accounts/abi/argument.go @@ -243,7 +243,7 @@ func (arguments Arguments) Pack(args ...interface{}) ([]byte, error) { // input offset is the bytes offset for packed output inputOffset := 0 for _, abiArg := range abiArgs { - inputOffset += getOffset(abiArg.Type) + inputOffset += getDynamicTypeOffset(abiArg.Type) } var ret []byte for i, a := range args { diff --git a/accounts/abi/type.go b/accounts/abi/type.go index 1a3fd1fe1e..f4c528c3ba 100644 --- a/accounts/abi/type.go +++ b/accounts/abi/type.go @@ -196,7 +196,7 @@ func (t Type) pack(v reflect.Value) ([]byte, error) { offset := 0 offsetReq := offsetRequired(*t.Elem) if offsetReq { - offset = getOffset(*t.Elem) * v.Len() + offset = getDynamicTypeOffset(*t.Elem) * v.Len() } var tail []byte for i := 0; i < v.Len(); i++ { @@ -231,8 +231,12 @@ func offsetRequired(t Type) bool { return t.T == StringTy || t.T == BytesTy || t.T == SliceTy || (t.T == ArrayTy && offsetRequired(*t.Elem)) } -// getOffset returns the offset to be added for t -func getOffset(t Type) int { +// getDynamicTypeOffset returns the offset for the type. +// See offsetRequired to know which types are considered dynamic. +// if the type t is an array and element type is not a dynamic type, then we consider it a static type and +// return 32 * size of array since length prefix is not required. +// If t is a dynamic type or element type(for slices and arrays) is dynamic, then we simply return 32 as offset. +func getDynamicTypeOffset(t Type) int { // if it is an array and there are no dynamic types // then the array is static type if t.T == ArrayTy && !offsetRequired(*t.Elem) {