abi/bind: fix error-handling in generated wrappers for functions returning structs (#22005)

Fixes the template used when generating code, which in some scenarios would lead to panic instead of returning an error.
This commit is contained in:
Connor Stein
2020-12-12 04:16:34 -05:00
committed by GitHub
parent 4d48980e74
commit 38c1d592b7
2 changed files with 42 additions and 0 deletions

View File

@ -304,6 +304,9 @@ var (
err := _{{$contract.Type}}.contract.Call(opts, &out, "{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}})
{{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}} = out[{{$i}}].({{bindtype .Type $structs}}){{end}}