accounts/abi: refactor to pass tests

This commit is contained in:
Oren Zakay 2017-11-12 09:59:35 +02:00
parent f31713c1df
commit cf40142f31
2 changed files with 12 additions and 14 deletions

View file

@ -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. // if we reach this part, there is only one output member from the contract event.
// for mobile, the result type is always a slice. // for mobile, the result type is always a slice.
var firstValue reflect.Value if reflect.Slice == value.Kind() && value.Len() >= 1 {
if reflect.Slice == value.Kind() { //check if it's not a byte slice
// take the first element if reflect.TypeOf([]byte{}) != value.Type() {
firstValue = value.Index(0).Elem() value = value.Index(0).Elem()
} else { }
firstValue = value
} }
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 err
} }
return nil return nil

View file

@ -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. // if we reach this part, there is only one output member from the contract method.
// for mobile, the result type is always a slice. // for mobile, the result type is always a slice.
var firstValue reflect.Value if reflect.Slice == value.Kind() && value.Len() >= 1 {
if reflect.Slice == value.Kind() { //check if it's not a byte slice
// take the first element if reflect.TypeOf([]byte{}) != value.Type() {
firstValue = value.Index(0).Elem() value = value.Index(0).Elem()
} else { }
firstValue = value
} }
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 err
} }
return nil return nil