Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abigen: fix duplicate struct definitions (#10157) #10164

Merged
merged 1 commit into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading