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

accounts/abi: resolve name conflict for methods starting with a number #26999

Merged
merged 9 commits into from
May 2, 2023
9 changes: 8 additions & 1 deletion accounts/abi/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package abi

import "fmt"
import (
"fmt"
"unicode"
)

// ResolveNameConflict returns the next available name for a given thing.
// This helper can be used for lots of purposes:
Expand All @@ -29,8 +32,12 @@ import "fmt"
//
// Name conflicts are mostly resolved by adding number suffix. e.g. if the abi contains
// Methods "send" and "send1", ResolveNameConflict would return "send2" for input "send".
// If a method name starts with a number an m is prepended (e.g. 1method -> m1method).
func ResolveNameConflict(rawName string, used func(string) bool) string {
name := rawName
if unicode.IsDigit(rune(name[0])) {
name = fmt.Sprintf("%s%s", "m", name)
}
ok := used(name)
for idx := 0; ok; idx++ {
name = fmt.Sprintf("%s%d", rawName, idx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also need to use the m-prefixed version. So maybe you need to set rawName to name

Copy link
Member Author

@MariusVanDerWijden MariusVanDerWijden Mar 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn now I see it, thanks will add a test

Expand Down