accounts/abi: fixed string and fixed size bytes packing

This commit is contained in:
Jeffrey Wilcke
2016-04-20 21:30:02 +02:00
parent c3d5250473
commit 4880868c88
6 changed files with 138 additions and 86 deletions

View File

@ -89,6 +89,7 @@ func NewType(t string) (typ Type, err error) {
return Type{}, err
}
typ.Elem = &sliceType
typ.stringKind = sliceType.stringKind + t[len(res[1]):]
return typ, nil
}
@ -110,6 +111,7 @@ func NewType(t string) (typ Type, err error) {
varSize = 256
t += "256"
}
typ.stringKind = t
switch varType {
case "int":
@ -149,7 +151,6 @@ func NewType(t string) (typ Type, err error) {
default:
return Type{}, fmt.Errorf("unsupported arg type: %s", t)
}
typ.stringKind = t
return
}
@ -181,3 +182,9 @@ func (t Type) pack(v reflect.Value) ([]byte, error) {
return packElement(t, v), nil
}
// 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)
}