Skip to content

Commit 4c524e6

Browse files
committed
add TryPack template method
1 parent 2958387 commit 4c524e6

File tree

6 files changed

+280
-40
lines changed

6 files changed

+280
-40
lines changed

accounts/abi/abigen/source2.go.tpl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,23 @@ var (
8989
{{ end }}
9090

9191
{{range .Calls}}
92-
// Pack{{.Normalized.Name}} is the Go binding used to pack the parameters required for calling
92+
// Pack{{.Normalized.Name}} is the Go binding used to pack the parameters required for calling, will panic for any error.
9393
// the contract method with ID 0x{{printf "%x" .Original.ID}}.
9494
//
9595
// Solidity: {{.Original.String}}
96-
func ({{ decapitalise $contract.Type}} *{{$contract.Type}}) Pack{{.Normalized.Name}}({{range .Normalized.Inputs}} {{.Name}} {{bindtype .Type $structs}}, {{end}}) ([]byte, error) {
96+
func ({{ decapitalise $contract.Type}} *{{$contract.Type}}) Pack{{.Normalized.Name}}({{range .Normalized.Inputs}} {{.Name}} {{bindtype .Type $structs}}, {{end}}) []byte {
97+
enc, err := {{ decapitalise $contract.Type}}.abi.Pack("{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}})
98+
if err != nil {
99+
panic(err)
100+
}
101+
return enc
102+
}
103+
104+
// Pack{{.Normalized.Name}} is the Go binding used to pack the parameters required for calling, return error if it failed to pack.
105+
// the contract method with ID 0x{{printf "%x" .Original.ID}}.
106+
//
107+
// Solidity: {{.Original.String}}
108+
func ({{ decapitalise $contract.Type}} *{{$contract.Type}}) TryPack{{.Normalized.Name}}({{range .Normalized.Inputs}} {{.Name}} {{bindtype .Type $structs}}, {{end}}) ([]byte, error) {
97109
return {{ decapitalise $contract.Type}}.abi.Pack("{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}})
98110
}
99111

accounts/abi/bind/v2/internal/contracts/db/bindings.go

Lines changed: 70 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

accounts/abi/bind/v2/internal/contracts/events/bindings.go

Lines changed: 28 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)