diff options
Diffstat (limited to 'accounts/abi/bind/bind.go')
-rw-r--r-- | accounts/abi/bind/bind.go | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/accounts/abi/bind/bind.go b/accounts/abi/bind/bind.go index 4dce79b77..8175e3cb9 100644 --- a/accounts/abi/bind/bind.go +++ b/accounts/abi/bind/bind.go @@ -304,8 +304,15 @@ var methodNormalizer = map[Lang]func(string) string{ LangJava: decapitalise, } -// capitalise makes the first character of a string upper case. +// capitalise makes the first character of a string upper case, also removing any +// prefixing underscores from the variable names. func capitalise(input string) string { + for len(input) > 0 && input[0] == '_' { + input = input[1:] + } + if len(input) == 0 { + return "" + } return strings.ToUpper(input[:1]) + input[1:] } @@ -315,15 +322,24 @@ func decapitalise(input string) string { } // structured checks whether a method has enough information to return a proper -// Go struct ot if flat returns are needed. +// Go struct or if flat returns are needed. func structured(method abi.Method) bool { if len(method.Outputs) < 2 { return false } + exists := make(map[string]bool) for _, out := range method.Outputs { + // If the name is anonymous, we can't organize into a struct if out.Name == "" { return false } + // If the field name is empty when normalized or collides (var, Var, _var, _Var), + // we can't organize into a struct + field := capitalise(out.Name) + if field == "" || exists[field] { + return false + } + exists[field] = true } return true } |