diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2016-04-21 03:16:21 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2016-04-28 18:41:37 +0800 |
commit | e0dc45fce2276fcabae8dca61dc766f98dde23e2 (patch) | |
tree | 8f2b56cecb27315012af2fda4e31b9e96dd8d0cf /accounts/abi/abi.go | |
parent | 5127ec10cb84a615f4d5b314e4c3c102efefe4c9 (diff) | |
download | go-tangerine-e0dc45fce2276fcabae8dca61dc766f98dde23e2.tar go-tangerine-e0dc45fce2276fcabae8dca61dc766f98dde23e2.tar.gz go-tangerine-e0dc45fce2276fcabae8dca61dc766f98dde23e2.tar.bz2 go-tangerine-e0dc45fce2276fcabae8dca61dc766f98dde23e2.tar.lz go-tangerine-e0dc45fce2276fcabae8dca61dc766f98dde23e2.tar.xz go-tangerine-e0dc45fce2276fcabae8dca61dc766f98dde23e2.tar.zst go-tangerine-e0dc45fce2276fcabae8dca61dc766f98dde23e2.zip |
accounts/abi: fixed strict go-like unpacking
Diffstat (limited to 'accounts/abi/abi.go')
-rw-r--r-- | accounts/abi/abi.go | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index 82ea4a0d5..e7cf4aac7 100644 --- a/accounts/abi/abi.go +++ b/accounts/abi/abi.go @@ -180,12 +180,33 @@ func toGoType(i int, t Argument, output []byte) (interface{}, error) { returnOutput = output[index : index+32] } - // cast bytes to abi return type + // convert the bytes to whatever is specified by the ABI. switch t.Type.T { - case IntTy: - return common.BytesToBig(returnOutput), nil - case UintTy: - return common.BytesToBig(returnOutput), nil + case IntTy, UintTy: + bigNum := common.BytesToBig(returnOutput) + + // If the type is a integer convert to the integer type + // specified by the ABI. + switch t.Type.Kind { + case reflect.Uint8: + return uint8(bigNum.Uint64()), nil + case reflect.Uint16: + return uint16(bigNum.Uint64()), nil + case reflect.Uint32: + return uint32(bigNum.Uint64()), nil + case reflect.Uint64: + return uint64(bigNum.Uint64()), nil + case reflect.Int8: + return uint8(bigNum.Int64()), nil + case reflect.Int16: + return uint16(bigNum.Int64()), nil + case reflect.Int32: + return uint32(bigNum.Int64()), nil + case reflect.Int64: + return uint64(bigNum.Int64()), nil + case reflect.Ptr: + return bigNum, nil + } case BoolTy: return common.BytesToBig(returnOutput).Uint64() > 0, nil case AddressTy: |