Skip to content

Commit

Permalink
abigen: fix duplicate struct definitions (#10157)
Browse files Browse the repository at this point in the history
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">
  • Loading branch information
taratorio committed May 1, 2024
1 parent 82262fe commit 52f7e85
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions accounts/abi/bind/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,16 @@ var tmplSource = map[Lang]string{
// tmplSourceGo is the Go source template that the generated Go contract binding
// is based on.
const tmplSourceGo = `
// Code generated - DO NOT EDIT.
// Code generated by abigen. DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.
package {{.Package}}
import (
"math/big"
"strings"
{{range .Contracts}}
{{$stop := false}}
{{range .Transacts}}
{{if ne (len .Normalized.Inputs) 0}}
"fmt"
"reflect"
{{$stop = true}}
{{break}}
{{end}}
{{end}}
{{if $stop}}
{{break}}
{{end}}
{{end}}
"fmt"
"reflect"
ethereum "github.com/ledgerwatch/erigon"
"github.com/ledgerwatch/erigon/accounts/abi"
Expand All @@ -123,6 +110,8 @@ var (
_ = libcommon.Big1
_ = types.BloomLookup
_ = event.NewSubscription
_ = fmt.Errorf
_ = reflect.ValueOf
)
{{$structs := .Structs}}
Expand Down Expand Up @@ -379,16 +368,16 @@ var (
{{range .Transacts}}
{{if ne (len .Normalized.Inputs) 0}}
// {{.Normalized.Name}}Params is an auto generated read-only Go binding of transcaction calldata params
type {{.Normalized.Name}}Params struct {
// {{$metaType}}{{.Normalized.Name}}Params is an auto generated read-only Go binding of transcaction calldata params
type {{$metaType}}{{.Normalized.Name}}Params struct {
{{range $i, $_ := .Normalized.Inputs}} Param_{{.Name}} {{bindtype .Type $structs}}
{{end}}
}
// Parse {{.Normalized.Name}} method from calldata of a transaction
//
// Solidity: {{.Original.String}}
func Parse{{.Normalized.Name}}(calldata []byte) (*{{.Normalized.Name}}Params, error) {
func Parse{{$metaType}}{{.Normalized.Name}}Params(calldata []byte) (*{{$metaType}}{{.Normalized.Name}}Params, error) {
if len(calldata) <= 4 {
return nil, fmt.Errorf("invalid calldata input")
}
Expand All @@ -403,7 +392,7 @@ var (
return nil, fmt.Errorf("failed to unpack {{.Original.Name}} params data: %w", err)
}
var paramsResult = new({{.Normalized.Name}}Params)
var paramsResult = new({{$metaType}}{{.Normalized.Name}}Params)
value := reflect.ValueOf(paramsResult).Elem()
if value.NumField() != len(out) {
Expand All @@ -413,7 +402,7 @@ var (
{{range $i, $t := .Normalized.Inputs}}
out{{$i}} := *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}){{end}}
return &{{.Normalized.Name}}Params{
return &{{$metaType}}{{.Normalized.Name}}Params{
{{range $i, $_ := .Normalized.Inputs}} Param_{{.Name}} : out{{$i}},{{end}}
}, nil
}
Expand Down

0 comments on commit 52f7e85

Please sign in to comment.