Skip to content

Commit 52f7e85

Browse files
committed
abigen: fix duplicate struct definitions (#10157)
fixes a 2nd regression introduced by - #7593 - it generates duplicate struct types in the same package (check screenshot below) - also found a better way to fix the first regression with unused imports (improvement over #10091) <img width="1438" alt="Screenshot 2024-04-30 at 17 30 42" src="https://github.com/ledgerwatch/erigon/assets/94537774/154d484b-4b67-4104-8a6e-eac2423e1c0e">
1 parent 82262fe commit 52f7e85

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

accounts/abi/bind/template.go

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,16 @@ var tmplSource = map[Lang]string{
8282
// tmplSourceGo is the Go source template that the generated Go contract binding
8383
// is based on.
8484
const tmplSourceGo = `
85-
// Code generated - DO NOT EDIT.
85+
// Code generated by abigen. DO NOT EDIT.
8686
// This file is a generated binding and any manual changes will be lost.
8787
8888
package {{.Package}}
8989
9090
import (
9191
"math/big"
9292
"strings"
93-
94-
{{range .Contracts}}
95-
{{$stop := false}}
96-
{{range .Transacts}}
97-
{{if ne (len .Normalized.Inputs) 0}}
98-
"fmt"
99-
"reflect"
100-
{{$stop = true}}
101-
{{break}}
102-
{{end}}
103-
{{end}}
104-
{{if $stop}}
105-
{{break}}
106-
{{end}}
107-
{{end}}
93+
"fmt"
94+
"reflect"
10895
10996
ethereum "github.com/ledgerwatch/erigon"
11097
"github.com/ledgerwatch/erigon/accounts/abi"
@@ -123,6 +110,8 @@ var (
123110
_ = libcommon.Big1
124111
_ = types.BloomLookup
125112
_ = event.NewSubscription
113+
_ = fmt.Errorf
114+
_ = reflect.ValueOf
126115
)
127116
128117
{{$structs := .Structs}}
@@ -379,16 +368,16 @@ var (
379368
{{range .Transacts}}
380369
{{if ne (len .Normalized.Inputs) 0}}
381370
382-
// {{.Normalized.Name}}Params is an auto generated read-only Go binding of transcaction calldata params
383-
type {{.Normalized.Name}}Params struct {
371+
// {{$metaType}}{{.Normalized.Name}}Params is an auto generated read-only Go binding of transcaction calldata params
372+
type {{$metaType}}{{.Normalized.Name}}Params struct {
384373
{{range $i, $_ := .Normalized.Inputs}} Param_{{.Name}} {{bindtype .Type $structs}}
385374
{{end}}
386375
}
387376
388377
// Parse {{.Normalized.Name}} method from calldata of a transaction
389378
//
390379
// Solidity: {{.Original.String}}
391-
func Parse{{.Normalized.Name}}(calldata []byte) (*{{.Normalized.Name}}Params, error) {
380+
func Parse{{$metaType}}{{.Normalized.Name}}Params(calldata []byte) (*{{$metaType}}{{.Normalized.Name}}Params, error) {
392381
if len(calldata) <= 4 {
393382
return nil, fmt.Errorf("invalid calldata input")
394383
}
@@ -403,7 +392,7 @@ var (
403392
return nil, fmt.Errorf("failed to unpack {{.Original.Name}} params data: %w", err)
404393
}
405394
406-
var paramsResult = new({{.Normalized.Name}}Params)
395+
var paramsResult = new({{$metaType}}{{.Normalized.Name}}Params)
407396
value := reflect.ValueOf(paramsResult).Elem()
408397
409398
if value.NumField() != len(out) {
@@ -413,7 +402,7 @@ var (
413402
{{range $i, $t := .Normalized.Inputs}}
414403
out{{$i}} := *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}){{end}}
415404
416-
return &{{.Normalized.Name}}Params{
405+
return &{{$metaType}}{{.Normalized.Name}}Params{
417406
{{range $i, $_ := .Normalized.Inputs}} Param_{{.Name}} : out{{$i}},{{end}}
418407
}, nil
419408
}

0 commit comments

Comments
 (0)