mirror of
https://github.com/forta-network/go-multicall.git
synced 2026-04-30 05:12:54 +00:00
Outputs type supports nil
This commit is contained in:
parent
1fbee12081
commit
12c2d287e9
1 changed files with 11 additions and 6 deletions
17
call.go
17
call.go
|
|
@ -2,6 +2,7 @@ package multicall
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
|
@ -75,20 +76,24 @@ func (call *Call) AllowFailure() *Call {
|
||||||
|
|
||||||
// Unpack unpacks and converts EVM outputs and sets struct fields.
|
// Unpack unpacks and converts EVM outputs and sets struct fields.
|
||||||
func (call *Call) Unpack(b []byte) error {
|
func (call *Call) Unpack(b []byte) error {
|
||||||
t := reflect.ValueOf(call.Outputs)
|
|
||||||
if t.Kind() == reflect.Pointer {
|
|
||||||
t = t.Elem()
|
|
||||||
}
|
|
||||||
out, err := call.Contract.ABI.Unpack(call.Method, b)
|
out, err := call.Contract.ABI.Unpack(call.Method, b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to unpack '%s' outputs: %v", call.Method, err)
|
return fmt.Errorf("failed to unpack '%s' outputs: %v", call.Method, err)
|
||||||
}
|
}
|
||||||
|
if call.Outputs == nil {
|
||||||
if t.Kind() != reflect.Struct {
|
|
||||||
call.Outputs = out
|
call.Outputs = out
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t := reflect.ValueOf(call.Outputs)
|
||||||
|
if t.Kind() == reflect.Pointer {
|
||||||
|
t = t.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
|
if t.Kind() != reflect.Struct {
|
||||||
|
return errors.New("outputs type is not a struct")
|
||||||
|
}
|
||||||
|
|
||||||
fieldCount := t.NumField()
|
fieldCount := t.NumField()
|
||||||
for i := 0; i < fieldCount; i++ {
|
for i := 0; i < fieldCount; i++ {
|
||||||
field := t.Field(i)
|
field := t.Field(i)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue