Skip to content

Commit

Permalink
accounts/abi/bind: fix duplicate field names in the generated go struct
Browse files Browse the repository at this point in the history
  • Loading branch information
lwhile authored and rjl493456442 committed May 24, 2022
1 parent ba47d80 commit b958481
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions accounts/abi/bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit b958481

Please sign in to comment.