mirror of
https://github.com/forta-network/go-multicall.git
synced 2026-02-26 15:47:23 +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 (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
|
|
@ -75,20 +76,24 @@ func (call *Call) AllowFailure() *Call {
|
|||
|
||||
// Unpack unpacks and converts EVM outputs and sets struct fields.
|
||||
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)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to unpack '%s' outputs: %v", call.Method, err)
|
||||
}
|
||||
|
||||
if t.Kind() != reflect.Struct {
|
||||
if call.Outputs == nil {
|
||||
call.Outputs = out
|
||||
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()
|
||||
for i := 0; i < fieldCount; i++ {
|
||||
field := t.Field(i)
|
||||
|
|
|
|||
Loading…
Reference in a new issue