From 76eaf819074adbf513d118e4c1590909b5e8b894 Mon Sep 17 00:00:00 2001 From: taratorio <94537774+taratorio@users.noreply.github.com> Date: Wed, 1 May 2024 12:28:10 +0300 Subject: [PATCH 1/6] abigen: fix duplicate struct definitions --- 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..e7cde9278f0 100644 --- a/accounts/abi/bind/template.go +++ b/accounts/abi/bind/template.go @@ -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,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 { + // {{.Type}}{{.Normalized.Name}}Params is an auto generated read-only Go binding of transcaction calldata params + type {{.Type}}{{.Normalized.Name}}Params struct { {{range $i, $_ := .Normalized.Inputs}} Param_{{.Name}} {{bindtype .Type $structs}} {{end}} } - // Parse {{.Normalized.Name}} method from calldata of a transaction + // Parse {{.Type}}{{.Normalized.Name}} method from calldata of a transaction // // Solidity: {{.Original.String}} - func Parse{{.Normalized.Name}}(calldata []byte) (*{{.Normalized.Name}}Params, error) { + func Parse{{.Type}}{{.Normalized.Name}}(calldata []byte) (*{{.Type}}{{.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({{.Type}}{{.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 &{{.Type}}{{.Normalized.Name}}Params{ {{range $i, $_ := .Normalized.Inputs}} Param_{{.Name}} : out{{$i}},{{end}} }, nil } From fb163602f245bcaf7684219915096b45b50dc2f4 Mon Sep 17 00:00:00 2001 From: taratorio <94537774+taratorio@users.noreply.github.com> Date: Wed, 1 May 2024 12:30:29 +0300 Subject: [PATCH 2/6] abigen: add code generated by info --- accounts/abi/bind/template.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts/abi/bind/template.go b/accounts/abi/bind/template.go index e7cde9278f0..c97436e083f 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}} From 269bdc415c38a943f67caca76993b73cad3a0f11 Mon Sep 17 00:00:00 2001 From: taratorio <94537774+taratorio@users.noreply.github.com> Date: Wed, 1 May 2024 12:38:41 +0300 Subject: [PATCH 3/6] abigen: add code generated by info --- accounts/abi/bind/template.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts/abi/bind/template.go b/accounts/abi/bind/template.go index c97436e083f..c3b183e8718 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 by abigen - 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}} From bfc30bd3586abe109ce142af558826f1ff444f02 Mon Sep 17 00:00:00 2001 From: taratorio <94537774+taratorio@users.noreply.github.com> Date: Wed, 1 May 2024 12:48:10 +0300 Subject: [PATCH 4/6] abigen: use metaType var --- accounts/abi/bind/template.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/accounts/abi/bind/template.go b/accounts/abi/bind/template.go index c3b183e8718..cf34e1c4d6e 100644 --- a/accounts/abi/bind/template.go +++ b/accounts/abi/bind/template.go @@ -368,16 +368,16 @@ var ( {{range .Transacts}} {{if ne (len .Normalized.Inputs) 0}} - // {{.Type}}{{.Normalized.Name}}Params is an auto generated read-only Go binding of transcaction calldata params - type {{.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 {{.Type}}{{.Normalized.Name}} method from calldata of a transaction + // Parse {{$metaType}}{{.Normalized.Name}} method from calldata of a transaction // // Solidity: {{.Original.String}} - func Parse{{.Type}}{{.Normalized.Name}}(calldata []byte) (*{{.Type}}{{.Normalized.Name}}Params, error) { + func Parse{{$metaType}}{{.Normalized.Name}}(calldata []byte) (*{{$metaType}}{{.Normalized.Name}}Params, error) { if len(calldata) <= 4 { return nil, fmt.Errorf("invalid calldata input") } @@ -392,7 +392,7 @@ var ( return nil, fmt.Errorf("failed to unpack {{.Original.Name}} params data: %w", err) } - var paramsResult = new({{.Type}}{{.Normalized.Name}}Params) + var paramsResult = new({{$metaType}}{{.Normalized.Name}}Params) value := reflect.ValueOf(paramsResult).Elem() if value.NumField() != len(out) { @@ -402,7 +402,7 @@ var ( {{range $i, $t := .Normalized.Inputs}} out{{$i}} := *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}){{end}} - return &{{.Type}}{{.Normalized.Name}}Params{ + return &{{$metaType}}{{.Normalized.Name}}Params{ {{range $i, $_ := .Normalized.Inputs}} Param_{{.Name}} : out{{$i}},{{end}} }, nil } From 9a1876feb87e9a3d560c30f410dea801a18065ce Mon Sep 17 00:00:00 2001 From: taratorio <94537774+taratorio@users.noreply.github.com> Date: Wed, 1 May 2024 16:48:21 +0300 Subject: [PATCH 5/6] abigen: more descriptive func name for parse params --- accounts/abi/bind/template.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts/abi/bind/template.go b/accounts/abi/bind/template.go index cf34e1c4d6e..b37519d222d 100644 --- a/accounts/abi/bind/template.go +++ b/accounts/abi/bind/template.go @@ -377,7 +377,7 @@ var ( // Parse {{$metaType}}{{.Normalized.Name}} method from calldata of a transaction // // Solidity: {{.Original.String}} - func Parse{{$metaType}}{{.Normalized.Name}}(calldata []byte) (*{{$metaType}}{{.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") } From a42c82328c3833fb99d824802bf55731e54a801b Mon Sep 17 00:00:00 2001 From: taratorio <94537774+taratorio@users.noreply.github.com> Date: Wed, 1 May 2024 17:15:55 +0300 Subject: [PATCH 6/6] keep original doc comment --- accounts/abi/bind/template.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts/abi/bind/template.go b/accounts/abi/bind/template.go index b37519d222d..3caa889fd00 100644 --- a/accounts/abi/bind/template.go +++ b/accounts/abi/bind/template.go @@ -374,7 +374,7 @@ var ( {{end}} } - // Parse {{$metaType}}{{.Normalized.Name}} method from calldata of a transaction + // Parse {{.Normalized.Name}} method from calldata of a transaction // // Solidity: {{.Original.String}} func Parse{{$metaType}}{{.Normalized.Name}}Params(calldata []byte) (*{{$metaType}}{{.Normalized.Name}}Params, error) {