accounts/abi: differentiate between static and dynamic arrays (#3121)

solves #3119

Signed-off-by: VoR0220 <rj@erisindustries.com>
This commit is contained in:
RJ
2016-11-03 17:25:19 -05:00
committed by Jeffrey Wilcke
parent ed2bc7fbe9
commit 2ad5dba50a
4 changed files with 65 additions and 27 deletions

View File

@ -170,6 +170,7 @@ func (t Type) pack(v reflect.Value) ([]byte, error) {
if (t.IsSlice || t.IsArray) && t.T != BytesTy && t.T != FixedBytesTy {
var packed []byte
for i := 0; i < v.Len(); i++ {
val, err := t.Elem.pack(v.Index(i))
if err != nil {
@ -177,7 +178,11 @@ func (t Type) pack(v reflect.Value) ([]byte, error) {
}
packed = append(packed, val...)
}
return packBytesSlice(packed, v.Len()), nil
if t.IsSlice {
return packBytesSlice(packed, v.Len()), nil
} else if t.IsArray {
return packed, nil
}
}
return packElement(t, v), nil
@ -186,5 +191,5 @@ func (t Type) pack(v reflect.Value) ([]byte, error) {
// requireLengthPrefix returns whether the type requires any sort of length
// prefixing.
func (t Type) requiresLengthPrefix() bool {
return t.T != FixedBytesTy && (t.T == StringTy || t.T == BytesTy || t.IsSlice || t.IsArray)
return t.T != FixedBytesTy && (t.T == StringTy || t.T == BytesTy || t.IsSlice)
}