From f31713c1dfd7252abd1e18194dd93ceec480764a Mon Sep 17 00:00:00 2001 From: Oren Zakay Date: Mon, 30 Oct 2017 14:53:27 +0200 Subject: [PATCH 1/2] accounts/abi: fix singleUnpack for mobile until now calling a contract function with a single result failed this commit fixes #15387 #14832 --- accounts/abi/event.go | 13 ++++++++++++- accounts/abi/method.go | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/accounts/abi/event.go b/accounts/abi/event.go index 44ed7b8df2..14819962a7 100644 --- a/accounts/abi/event.go +++ b/accounts/abi/event.go @@ -130,7 +130,18 @@ func (e Event) singleUnpack(v interface{}, output []byte) error { if err != nil { return err } - if err := set(value, reflect.ValueOf(marshalledValue), e.Inputs[0]); err != nil { + + // if we reach this part, there is only one output member from the contract event. + // for mobile, the result type is always a slice. + var firstValue reflect.Value + if reflect.Slice == value.Kind() { + // take the first element + firstValue = value.Index(0).Elem() + } else { + firstValue = value + } + + if err := set(firstValue, reflect.ValueOf(marshalledValue), e.Inputs[0]); err != nil { return err } return nil diff --git a/accounts/abi/method.go b/accounts/abi/method.go index d8838e9ed6..4c52c5f6eb 100644 --- a/accounts/abi/method.go +++ b/accounts/abi/method.go @@ -150,7 +150,18 @@ func (method Method) singleUnpack(v interface{}, output []byte) error { if err != nil { return err } - if err := set(value, reflect.ValueOf(marshalledValue), method.Outputs[0]); err != nil { + + // if we reach this part, there is only one output member from the contract method. + // for mobile, the result type is always a slice. + var firstValue reflect.Value + if reflect.Slice == value.Kind() { + // take the first element + firstValue = value.Index(0).Elem() + } else { + firstValue = value + } + + if err := set(firstValue, reflect.ValueOf(marshalledValue), method.Outputs[0]); err != nil { return err } return nil From cf40142f3111148b99b9a4c36503a99e175f1cc1 Mon Sep 17 00:00:00 2001 From: Oren Zakay Date: Sun, 12 Nov 2017 09:59:35 +0200 Subject: [PATCH 2/2] accounts/abi: refactor to pass tests --- accounts/abi/event.go | 13 ++++++------- accounts/abi/method.go | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/accounts/abi/event.go b/accounts/abi/event.go index 14819962a7..a69ebf86a5 100644 --- a/accounts/abi/event.go +++ b/accounts/abi/event.go @@ -133,15 +133,14 @@ func (e Event) singleUnpack(v interface{}, output []byte) error { // if we reach this part, there is only one output member from the contract event. // for mobile, the result type is always a slice. - var firstValue reflect.Value - if reflect.Slice == value.Kind() { - // take the first element - firstValue = value.Index(0).Elem() - } else { - firstValue = value + if reflect.Slice == value.Kind() && value.Len() >= 1 { + //check if it's not a byte slice + if reflect.TypeOf([]byte{}) != value.Type() { + value = value.Index(0).Elem() + } } - if err := set(firstValue, reflect.ValueOf(marshalledValue), e.Inputs[0]); err != nil { + if err := set(value, reflect.ValueOf(marshalledValue), e.Inputs[0]); err != nil { return err } return nil diff --git a/accounts/abi/method.go b/accounts/abi/method.go index 4c52c5f6eb..185f518505 100644 --- a/accounts/abi/method.go +++ b/accounts/abi/method.go @@ -153,15 +153,14 @@ func (method Method) singleUnpack(v interface{}, output []byte) error { // if we reach this part, there is only one output member from the contract method. // for mobile, the result type is always a slice. - var firstValue reflect.Value - if reflect.Slice == value.Kind() { - // take the first element - firstValue = value.Index(0).Elem() - } else { - firstValue = value + if reflect.Slice == value.Kind() && value.Len() >= 1 { + //check if it's not a byte slice + if reflect.TypeOf([]byte{}) != value.Type() { + value = value.Index(0).Elem() + } } - if err := set(firstValue, reflect.ValueOf(marshalledValue), method.Outputs[0]); err != nil { + if err := set(value, reflect.ValueOf(marshalledValue), method.Outputs[0]); err != nil { return err } return nil