Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions accounts/abi/abigen/source2.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var (
{{ end }}

{{range .Calls}}
// Pack{{.Normalized.Name}} is the Go binding used to pack the parameters required for calling
// Pack{{.Normalized.Name}} is the Go binding used to pack the parameters required for calling, will panic for any error.
// the contract method with ID 0x{{printf "%x" .Original.ID}}.
//
// Solidity: {{.Original.String}}
Expand All @@ -101,6 +101,14 @@ var (
return enc
}

// Pack{{.Normalized.Name}} is the Go binding used to pack the parameters required for calling, return error if it failed to pack.
// the contract method with ID 0x{{printf "%x" .Original.ID}}.
//
// Solidity: {{.Original.String}}
func ({{ decapitalise $contract.Type}} *{{$contract.Type}}) TryPack{{.Normalized.Name}}({{range .Normalized.Inputs}} {{.Name}} {{bindtype .Type $structs}}, {{end}}) ([]byte, error) {
return {{ decapitalise $contract.Type}}.abi.Pack("{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}})
}

{{/* Unpack method is needed only when there are return args */}}
{{if .Normalized.Outputs }}
{{ if .Structured }}
Expand All @@ -117,24 +125,23 @@ var (
//
// Solidity: {{.Original.String}}
func ({{ decapitalise $contract.Type}} *{{$contract.Type}}) Unpack{{.Normalized.Name}}(data []byte) (
{{- if .Structured}} {{.Normalized.Name}}Output,{{else}}
{{- if .Structured}} *{{.Normalized.Name}}Output,{{else}}
{{- range .Normalized.Outputs}} {{bindtype .Type $structs}},{{- end }}
{{- end }} error) {
out, err := {{ decapitalise $contract.Type}}.abi.Unpack("{{.Original.Name}}", data)
{{- if .Structured}}
outstruct := new({{.Normalized.Name}}Output)
if err != nil {
return *outstruct, err
return nil, err
}
outstruct := new({{.Normalized.Name}}Output)
{{- range $i, $t := .Normalized.Outputs}}
{{- if ispointertype .Type}}
outstruct.{{capitalise .Name}} = abi.ConvertType(out[{{$i}}], new({{underlyingbindtype .Type }})).({{bindtype .Type $structs}})
{{- else }}
outstruct.{{capitalise .Name}} = *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}})
{{- end }}
{{- end }}
return *outstruct, err
{{else}}
return outstruct, nil{{else}}
if err != nil {
return {{range $i, $_ := .Normalized.Outputs}}{{if ispointertype .Type}}new({{underlyingbindtype .Type }}), {{else}}*new({{bindtype .Type $structs}}), {{end}}{{end}} err
}
Expand All @@ -145,8 +152,7 @@ var (
out{{$i}} := *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}})
{{- end }}
{{- end}}
return {{range $i, $t := .Normalized.Outputs}}out{{$i}}, {{end}} err
{{- end}}
return {{range $i, $t := .Normalized.Outputs}}out{{$i}}, {{end}} nil{{- end}}
}
{{end}}
{{end}}
Expand Down
74 changes: 56 additions & 18 deletions accounts/abi/bind/v2/internal/contracts/db/bindings.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions accounts/abi/bind/v2/internal/contracts/events/bindings.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading