accounts/abi: ABI fixes & added types

Changed field `input` to new `inputs`. Addad Hash and Address as input
types.

Added bytes[N] and N validation
This commit is contained in:
Jeffrey Wilcke
2015-10-28 22:57:21 +01:00
parent 6b5a42a15c
commit 1f72952f04
3 changed files with 80 additions and 21 deletions

View File

@ -43,7 +43,7 @@ type Type struct {
stringKind string // holds the unparsed string for deriving signatures
}
// New type returns a fully parsed Type given by the input string or an error if it can't be parsed.
// NewType returns a fully parsed Type given by the input string or an error if it can't be parsed.
//
// Strings can be in the format of:
//
@ -130,6 +130,10 @@ func NewType(t string) (typ Type, err error) {
if vsize > 0 {
typ.Size = 32
}
case "bytes":
typ.Kind = reflect.Slice
typ.Type = byte_ts
typ.Size = vsize
default:
return Type{}, fmt.Errorf("unsupported arg type: %s", t)
}
@ -200,7 +204,13 @@ func (t Type) pack(v interface{}) ([]byte, error) {
} else {
return common.LeftPadBytes(common.Big0.Bytes(), 32), nil
}
case reflect.Array:
if v, ok := value.Interface().(common.Address); ok {
return t.pack(v[:])
} else if v, ok := value.Interface().(common.Hash); ok {
return t.pack(v[:])
}
}
panic("unreached")
return nil, fmt.Errorf("ABI: bad input given %T", value.Kind())
}