skip unpack method when no return args

This commit is contained in:
Sina Mahmoodi 2023-03-01 13:32:34 +03:30 committed by Jared Wasinger
parent 724f77e3ec
commit dcf1318a24
2 changed files with 23 additions and 20 deletions

View File

@ -129,7 +129,7 @@ func BindV2(types []string, abis []string, bytecodes []string, fsigs []map[strin
if call.Structured { if call.Structured {
continue continue
} }
if len(call.Normalized.Outputs) == 1 { if len(call.Normalized.Outputs) < 2 {
continue continue
} }
// Build up dictionary of existing arg names. // Build up dictionary of existing arg names.

View File

@ -89,27 +89,30 @@ var (
return _{{$contract.Type}}.abi.Pack("{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}}) return _{{$contract.Type}}.abi.Pack("{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}})
} }
func (_{{$contract.Type}} *{{$contract.Type}}) Unpack{{.Normalized.Name}}(data []byte) ({{if .Structured}}struct{ {{range .Normalized.Outputs}}{{.Name}} {{bindtype .Type $structs}};{{end}} },{{else}}{{range .Normalized.Outputs}}{{bindtype .Type $structs}},{{end}}{{end}} error) { {{/* Unpack method is needed only when there are return args */}}
out, err := _{{$contract.Type}}.abi.Unpack("{{.Original.Name}}", data) {{if .Normalized.Outputs }}
{{if .Structured}} func (_{{$contract.Type}} *{{$contract.Type}}) Unpack{{.Normalized.Name}}(data []byte) ({{if .Structured}}struct{ {{range .Normalized.Outputs}}{{.Name}} {{bindtype .Type $structs}};{{end}} },{{else}}{{range .Normalized.Outputs}}{{bindtype .Type $structs}},{{end}}{{end}} error) {
outstruct := new(struct{ {{range .Normalized.Outputs}} {{.Name}} {{bindtype .Type $structs}}; {{end}} }) out, err := _{{$contract.Type}}.abi.Unpack("{{.Original.Name}}", data)
if err != nil { {{if .Structured}}
outstruct := new(struct{ {{range .Normalized.Outputs}} {{.Name}} {{bindtype .Type $structs}}; {{end}} })
if err != nil {
return *outstruct, err
}
{{range $i, $t := .Normalized.Outputs}}
outstruct.{{.Name}} = *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}){{end}}
return *outstruct, err return *outstruct, err
} {{else}}
{{range $i, $t := .Normalized.Outputs}} if err != nil {
outstruct.{{.Name}} = *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}){{end}} return {{range $i, $_ := .Normalized.Outputs}}*new({{bindtype .Type $structs}}), {{end}} err
}
{{range $i, $t := .Normalized.Outputs}}
out{{$i}} := *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}){{end}}
return *outstruct, err return {{range $i, $t := .Normalized.Outputs}}out{{$i}}, {{end}} err
{{else}} {{end}}
if err != nil {
return {{range $i, $_ := .Normalized.Outputs}}*new({{bindtype .Type $structs}}), {{end}} err
} }
{{range $i, $t := .Normalized.Outputs}} {{end}}
out{{$i}} := *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}){{end}}
return {{range $i, $t := .Normalized.Outputs}}out{{$i}}, {{end}} err
{{end}}
}
{{end}} {{end}}
{{range .Events}} {{range .Events}}