aboutsummaryrefslogtreecommitdiffstats
path: root/lib/abi.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/abi.js')
-rw-r--r--lib/abi.js13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/abi.js b/lib/abi.js
index 13d6e45fc..8af10c382 100644
--- a/lib/abi.js
+++ b/lib/abi.js
@@ -175,7 +175,16 @@ var setupOutputTypes = function () {
/// Formats input right-aligned input bytes to int
/// @returns right-aligned input bytes formatted to int
var formatInt = function (value) {
- return value.length <= 8 ? +parseInt(value, 16) : hexToDec(value);
+ // check if it's negative number
+ // it it is, return two's complement
+ if (value.substr(0, 1).toLowerCase() === 'f') {
+ return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1);
+ }
+ return new BigNumber(value, 16);
+ };
+
+ var formatUInt = function (value) {
+ return new BigNumber(value, 16);
};
/// @returns right-aligned input bytes formatted to hex
@@ -199,7 +208,7 @@ var setupOutputTypes = function () {
};
return [
- { type: prefixedType('uint'), format: formatInt },
+ { type: prefixedType('uint'), format: formatUInt },
{ type: prefixedType('int'), format: formatInt },
{ type: prefixedType('hash'), format: formatHash },
{ type: prefixedType('string'), format: formatString },