aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/abi/bind/bind.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-12-30 05:20:02 +0800
committerGitHub <noreply@github.com>2017-12-30 05:20:02 +0800
commitb9731767af634ff90ae9b387bd035d9bc4b128e3 (patch)
treeb9e05770b293a06310948f2f2261f918e8b7064d /accounts/abi/bind/bind.go
parent36a10875c8c1a34aab851e3f65da48ccbb5367ce (diff)
downloaddexon-b9731767af634ff90ae9b387bd035d9bc4b128e3.tar
dexon-b9731767af634ff90ae9b387bd035d9bc4b128e3.tar.gz
dexon-b9731767af634ff90ae9b387bd035d9bc4b128e3.tar.bz2
dexon-b9731767af634ff90ae9b387bd035d9bc4b128e3.tar.lz
dexon-b9731767af634ff90ae9b387bd035d9bc4b128e3.tar.xz
dexon-b9731767af634ff90ae9b387bd035d9bc4b128e3.tar.zst
dexon-b9731767af634ff90ae9b387bd035d9bc4b128e3.zip
accounts/abi: handle named ouputs prefixed with underscores (#15766)
* accounts/abi: handle named ouputs prefixed with underscores * accounts/abi: handle collinding outputs for struct unpacks * accounts: handle purely underscore output names
Diffstat (limited to 'accounts/abi/bind/bind.go')
-rw-r--r--accounts/abi/bind/bind.go20
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
}