diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index 4c8f96680d..8045ece4a3 100644 --- a/accounts/abi/abi.go +++ b/accounts/abi/abi.go @@ -91,6 +91,8 @@ func (abi ABI) Unpack(v interface{}, name string, output []byte) (err error) { return err } + // since there can't be naming collisions with contracts and events, + // we need to decide whether we're calling a method or an event var unpack unpacker if method, ok := abi.Methods[name]; ok { unpack = method @@ -100,10 +102,10 @@ func (abi ABI) Unpack(v interface{}, name string, output []byte) (err error) { return fmt.Errorf("abi: could not locate named method or event.") } - if unpack.tupleReturn() { + // requires a struct to unpack into for a tuple return... + if unpack.isTupleReturn() { return unpack.tupleUnpack(v, output) } - return unpack.singleUnpack(v, output) } diff --git a/accounts/abi/pack.go b/accounts/abi/pack.go index 4d8a3f0318..072e805368 100644 --- a/accounts/abi/pack.go +++ b/accounts/abi/pack.go @@ -61,8 +61,9 @@ func packElement(t Type, reflectValue reflect.Value) []byte { reflectValue = mustArrayToByteSlice(reflectValue) } return common.RightPadBytes(reflectValue.Bytes(), 32) + default: + panic("abi: fatal error") } - panic("abi: fatal error") } // packNum packs the given number (using the reflect value) and will cast it to appropriate number representation @@ -74,6 +75,8 @@ func packNum(value reflect.Value) []byte { return U256(big.NewInt(value.Int())) case reflect.Ptr: return U256(value.Interface().(*big.Int)) + default: + panic("abi: fatal error") } - return nil + } diff --git a/accounts/abi/pack_test.go b/accounts/abi/pack_test.go index fcb5c75a85..36401ee677 100644 --- a/accounts/abi/pack_test.go +++ b/accounts/abi/pack_test.go @@ -435,7 +435,4 @@ func TestPackNumber(t *testing.T) { t.Errorf("test %d: pack mismatch: have %x, want %x", i, packed, tt.packed) } } - if packed := packNum(reflect.ValueOf("string")); packed != nil { - t.Errorf("expected 'string' to pack to nil. got %x instead", packed) - } } diff --git a/accounts/abi/reflect.go b/accounts/abi/reflect.go index 104d94232d..e953b77c18 100644 --- a/accounts/abi/reflect.go +++ b/accounts/abi/reflect.go @@ -73,15 +73,9 @@ func mustArrayToByteSlice(value reflect.Value) reflect.Value { func set(dst, src reflect.Value, output Argument) error { dstType := dst.Type() srcType := src.Type() - switch { - case dstType.AssignableTo(src.Type()): + case dstType.AssignableTo(srcType): dst.Set(src) - case dstType.Kind() == reflect.Array && srcType.Kind() == reflect.Slice: - if dst.Len() < output.Type.Size { - return fmt.Errorf("abi: cannot unmarshal src (len=%d) in to dst (len=%d)", output.Type.Size, dst.Len()) - } - reflect.Copy(dst, src) case dstType.Kind() == reflect.Interface: dst.Set(src) case dstType.Kind() == reflect.Ptr: