From b95848190734602e4aa2a1e9d9745bde93e1f216 Mon Sep 17 00:00:00 2001 From: lwhile Date: Sat, 21 May 2022 14:40:20 +0800 Subject: [PATCH] accounts/abi/bind: fix duplicate field names in the generated go struct #24627 --- accounts/abi/bind/bind.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/accounts/abi/bind/bind.go b/accounts/abi/bind/bind.go index 2bd8b6dde07f..6f5c3cc924d9 100644 --- a/accounts/abi/bind/bind.go +++ b/accounts/abi/bind/bind.go @@ -111,10 +111,17 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string] normalized.Name = normalizedName normalized.Inputs = make([]abi.Argument, len(original.Inputs)) copy(normalized.Inputs, original.Inputs) + // Used to save duplicated field name + inputNames := make(map[string]uint) for j, input := range normalized.Inputs { if input.Name == "" { normalized.Inputs[j].Name = fmt.Sprintf("arg%d", j) } + camelName := abi.ToCamelCase(input.Name) + inputNames[camelName] += 1 + if inputNames[camelName] > 1 { + normalized.Inputs[j].Name = fmt.Sprintf("%s%d", normalized.Inputs[j].Name, inputNames[camelName]-1) + } if hasStruct(input.Type) { bindStructType[lang](input.Type, structs) } @@ -154,10 +161,18 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string] normalized.Inputs = make([]abi.Argument, len(original.Inputs)) copy(normalized.Inputs, original.Inputs) + + // Used to save duplicated field name + inputNames := make(map[string]uint) for j, input := range normalized.Inputs { if input.Name == "" { normalized.Inputs[j].Name = fmt.Sprintf("arg%d", j) } + camelName := abi.ToCamelCase(input.Name) + inputNames[camelName] += 1 + if inputNames[camelName] > 1 { + normalized.Inputs[j].Name = fmt.Sprintf("%s%d", normalized.Inputs[j].Name, inputNames[camelName]-1) + } if hasStruct(input.Type) { bindStructType[lang](input.Type, structs) }