@@ -77,6 +77,21 @@ func isKeyWord(arg string) bool {
7777 return true
7878}
7979
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+
8095// Bind generates a Go wrapper around a contract ABI. This wrapper isn't meant
8196// to be used as is in client code, but rather as an intermediate struct which
8297// 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]
121136 callIdentifiers = make (map [string ]bool )
122137 transactIdentifiers = make (map [string ]bool )
123138 eventIdentifiers = make (map [string ]bool )
139+ dups = duplicates (evmABI .Methods )
124140 )
125141
126142 for _ , input := range evmABI .Constructor .Inputs {
@@ -132,12 +148,16 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
132148 for _ , original := range evmABI .Methods {
133149 // Normalize the method for capital cases and non-anonymous inputs/outputs
134150 normalized := original
135- normalizedName := methodNormalizer [lang ](alias (aliases , original .Name ))
136151 // Ensure there is no duplicated identifier
137152 var identifiers = callIdentifiers
138153 if ! original .IsConstant () {
139154 identifiers = transactIdentifiers
140155 }
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 ))
141161 // Name shouldn't start with a digit. It will make the generated code invalid.
142162 if len (normalizedName ) > 0 && unicode .IsDigit (rune (normalizedName [0 ])) {
143163 normalizedName = fmt .Sprintf ("M%s" , normalizedName )
0 commit comments