@@ -77,6 +77,21 @@ func isKeyWord(arg string) bool {
77
77
return true
78
78
}
79
79
80
+ func duplicates (methods map [string ]abi.Method ) map [string ]bool {
81
+ var (
82
+ identifiers = make (map [string ]bool )
83
+ dups = make (map [string ]bool )
84
+ )
85
+ for _ , method := range methods {
86
+ identifiers , dups := identifiers , dups
87
+ if identifiers [method .RawName ] {
88
+ dups [method .RawName ] = true
89
+ }
90
+ identifiers [method .RawName ] = true
91
+ }
92
+ return dups
93
+ }
94
+
80
95
// Bind generates a Go wrapper around a contract ABI. This wrapper isn't meant
81
96
// to be used as is in client code, but rather as an intermediate struct which
82
97
// enforces compile time type safety and naming convention opposed to having to
@@ -121,6 +136,7 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
121
136
callIdentifiers = make (map [string ]bool )
122
137
transactIdentifiers = make (map [string ]bool )
123
138
eventIdentifiers = make (map [string ]bool )
139
+ dups = duplicates (evmABI .Methods )
124
140
)
125
141
126
142
for _ , input := range evmABI .Constructor .Inputs {
@@ -132,12 +148,16 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
132
148
for _ , original := range evmABI .Methods {
133
149
// Normalize the method for capital cases and non-anonymous inputs/outputs
134
150
normalized := original
135
- normalizedName := methodNormalizer [lang ](alias (aliases , original .Name ))
136
151
// Ensure there is no duplicated identifier
137
152
var identifiers = callIdentifiers
138
153
if ! original .IsConstant () {
139
154
identifiers = transactIdentifiers
140
155
}
156
+ name := original .RawName
157
+ if dups [original .RawName ] {
158
+ name = fmt .Sprintf ("%s%x" , original .RawName , original .ID )
159
+ }
160
+ normalizedName := methodNormalizer [lang ](alias (aliases , name ))
141
161
// Name shouldn't start with a digit. It will make the generated code invalid.
142
162
if len (normalizedName ) > 0 && unicode .IsDigit (rune (normalizedName [0 ])) {
143
163
normalizedName = fmt .Sprintf ("M%s" , normalizedName )
0 commit comments