diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-04-05 23:20:50 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-04-05 23:20:50 +0800 |
commit | fc4fffd5ac341b6e7c9644045b66420f777940c5 (patch) | |
tree | 3f7fcb9ebad8c822e8d657ab43a2ca23ba27ce99 /accounts/abi/bind/bind.go | |
parent | 7e02105672cda92889a78db864a5701d78f45eb2 (diff) | |
download | dexon-fc4fffd5ac341b6e7c9644045b66420f777940c5.tar dexon-fc4fffd5ac341b6e7c9644045b66420f777940c5.tar.gz dexon-fc4fffd5ac341b6e7c9644045b66420f777940c5.tar.bz2 dexon-fc4fffd5ac341b6e7c9644045b66420f777940c5.tar.lz dexon-fc4fffd5ac341b6e7c9644045b66420f777940c5.tar.xz dexon-fc4fffd5ac341b6e7c9644045b66420f777940c5.tar.zst dexon-fc4fffd5ac341b6e7c9644045b66420f777940c5.zip |
accounts/abi/bind: support generating bindings for various arrays
Diffstat (limited to 'accounts/abi/bind/bind.go')
-rw-r--r-- | accounts/abi/bind/bind.go | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/accounts/abi/bind/bind.go b/accounts/abi/bind/bind.go index a9f21b21a..24fe9f770 100644 --- a/accounts/abi/bind/bind.go +++ b/accounts/abi/bind/bind.go @@ -23,6 +23,7 @@ package bind import ( "bytes" "fmt" + "regexp" "strings" "text/template" "unicode" @@ -122,31 +123,37 @@ func bindType(kind abi.Type) string { stringKind := kind.String() switch { - case stringKind == "address": - return "common.Address" - - case stringKind == "address[]": - return "[]common.Address" + case strings.HasPrefix(stringKind, "address"): + parts := regexp.MustCompile("address(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) + if len(parts) != 2 { + return stringKind + } + return fmt.Sprintf("%scommon.Address", parts[1]) case strings.HasPrefix(stringKind, "bytes"): - if stringKind == "bytes" { - return "[]byte" + parts := regexp.MustCompile("bytes([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) + if len(parts) != 3 { + return stringKind } - return fmt.Sprintf("[%s]byte", stringKind[5:]) + return fmt.Sprintf("%s[%s]byte", parts[2], parts[1]) - case strings.HasPrefix(stringKind, "int"): - switch stringKind[:3] { - case "8", "16", "32", "64": + case strings.HasPrefix(stringKind, "int") || strings.HasPrefix(stringKind, "uint"): + parts := regexp.MustCompile("(u)?int([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) + if len(parts) != 4 { return stringKind } - return "*big.Int" - - case strings.HasPrefix(stringKind, "uint"): - switch stringKind[:4] { + switch parts[2] { case "8", "16", "32", "64": + return fmt.Sprintf("%s%sint%s", parts[3], parts[1], parts[2]) + } + return fmt.Sprintf("%s*big.Int", parts[3]) + + case strings.HasPrefix(stringKind, "bool") || strings.HasPrefix(stringKind, "string"): + parts := regexp.MustCompile("([a-z]+)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) + if len(parts) != 3 { return stringKind } - return "*big.Int" + return fmt.Sprintf("%s%s", parts[2], parts[1]) default: return stringKind |