accounts/abi: begin redo

Signed-off-by: RJ Catalano <rj@monax.io>
This commit is contained in:
RJ Catalano 2017-06-27 15:40:32 -05:00
parent a0083e913a
commit 59b55e0652
No known key found for this signature in database
GPG key ID: D4AB109D9B5D6386
2 changed files with 9 additions and 5 deletions

View file

@ -93,6 +93,10 @@ func (abi ABI) Unpack(v interface{}, name string, output []byte) error {
return fmt.Errorf("abi: unmarshalling empty output")
}
if len(output)%32 != 0 {
return nil, fmt.Errorf("abi: improperly formatted output")
}
// make sure the passed value is a pointer
valueOf := reflect.ValueOf(v)
if reflect.Ptr != valueOf.Kind() {

View file

@ -98,10 +98,11 @@ func toGoSlice(i int, t Argument, output []byte) (interface{}, error) {
case FixedBytesTy:
inter = returnOutput
case SliceTy, ArrayTy:
inter, err = toGoSlice(i+index/32, t, output)
fmt.Println("Index: ", i+index/32)
/*inter, err = toGoSlice(i+index/32, t, output)
if err != nil {
return nil, err
}
}*/
default:
return nil, fmt.Errorf("abi: unsupported slice type passed in")
}
@ -163,9 +164,6 @@ func readBool(word []byte) (bool, error) {
// toGoType parses the input and casts it to the proper type defined by the ABI
// argument in T.
func toGoType(i int, t Argument, output []byte) (interface{}, error) {
if len(output)%32 != 0 {
return nil, fmt.Errorf("abi: improperly formatted output")
}
// we need to treat slices differently
if (t.Type.IsSlice || t.Type.IsArray) && t.Type.T != BytesTy && t.Type.T != StringTy && t.Type.T != FixedBytesTy && t.Type.T != FunctionTy {
return toGoSlice(i, t, output)
@ -215,3 +213,5 @@ func toGoType(i int, t Argument, output []byte) (interface{}, error) {
}
return nil, fmt.Errorf("abi: unknown type %v", t.Type.T)
}
// this needs a near complete redo