diff options
author | Matt K <1036969+mkrump@users.noreply.github.com> | 2018-12-29 18:32:58 +0800 |
---|---|---|
committer | Guillaume Ballet <gballet@gmail.com> | 2018-12-29 18:32:58 +0800 |
commit | a4af734328d50b9ea89405c7e5050065a8087946 (patch) | |
tree | 5741ded89a84cef4ca38faf10b5cc9094a1c7529 /accounts/abi/argument.go | |
parent | 735343430dec74a340f5c9a18822537e18165caa (diff) | |
download | dexon-a4af734328d50b9ea89405c7e5050065a8087946.tar dexon-a4af734328d50b9ea89405c7e5050065a8087946.tar.gz dexon-a4af734328d50b9ea89405c7e5050065a8087946.tar.bz2 dexon-a4af734328d50b9ea89405c7e5050065a8087946.tar.lz dexon-a4af734328d50b9ea89405c7e5050065a8087946.tar.xz dexon-a4af734328d50b9ea89405c7e5050065a8087946.tar.zst dexon-a4af734328d50b9ea89405c7e5050065a8087946.zip |
accounts/abi: change unpacking of abi fields w/ underscores (#16513)
* accounts/abi: fix name styling when unpacking abi fields w/ underscores
ABI fields with underscores that are being unpacked
into structs expect structs with following form:
int_one -> Int_one
whereas in abigen the generated structs are camelcased
int_one -> IntOne
so updated the unpack method to expect camelcased structs as well.
Diffstat (limited to 'accounts/abi/argument.go')
-rw-r--r-- | accounts/abi/argument.go | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/accounts/abi/argument.go b/accounts/abi/argument.go index 90fd9d05f..fdc6ff164 100644 --- a/accounts/abi/argument.go +++ b/accounts/abi/argument.go @@ -272,14 +272,13 @@ func (arguments Arguments) Pack(args ...interface{}) ([]byte, error) { return ret, nil } -// 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 "" +// ToCamelCase converts an under-score string to a camel-case string +func ToCamelCase(input string) string { + parts := strings.Split(input, "_") + for i, s := range parts { + if len(s) > 0 { + parts[i] = strings.ToUpper(s[:1]) + s[1:] + } } - return strings.ToUpper(input[:1]) + input[1:] + return strings.Join(parts, "") } |