From 52f7e8564ad8563aed01db8f098177f16299e272 Mon Sep 17 00:00:00 2001 From: milen <94537774+taratorio@users.noreply.github.com> Date: Wed, 1 May 2024 17:42:43 +0300 Subject: [PATCH] abigen: fix duplicate struct definitions (#10157) fixes a 2nd regression introduced by - https://github.com/ledgerwatch/erigon/pull/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 https://github.com/ledgerwatch/erigon/pull/10091) Screenshot 2024-04-30 at 17 30 42 --- accounts/abi/bind/template.go | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/accounts/abi/bind/template.go b/accounts/abi/bind/template.go index d80dacf1a0e..3caa889fd00 100644 --- a/accounts/abi/bind/template.go +++ b/accounts/abi/bind/template.go @@ -82,7 +82,7 @@ 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}} @@ -90,21 +90,8 @@ 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" @@ -123,6 +110,8 @@ var ( _ = libcommon.Big1 _ = types.BloomLookup _ = event.NewSubscription + _ = fmt.Errorf + _ = reflect.ValueOf ) {{$structs := .Structs}} @@ -379,8 +368,8 @@ 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}} } @@ -388,7 +377,7 @@ var ( // 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") } @@ -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) { @@ -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 }