diff options
Diffstat (limited to 'dist/ethereum.js')
-rw-r--r-- | dist/ethereum.js | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/dist/ethereum.js b/dist/ethereum.js index f2e3e570e..1dbb42d89 100644 --- a/dist/ethereum.js +++ b/dist/ethereum.js @@ -194,13 +194,19 @@ var toAbiInput = function (json, methodName, params) { return bytes; }; +/// Check if input value is negative +/// @param value is hex format +/// @returns true if it is negative, otherwise false +var signedIsNegative = function (value) { + return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1'; +}; + /// Formats input right-aligned input bytes to int /// @returns right-aligned input bytes formatted to int var formatOutputInt = function (value) { // check if it's negative number // it it is, return two's complement - var firstBit = new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1); - if (firstBit === '1') { + if (signedIsNegative(value)) { return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1); } return new BigNumber(value, 16); @@ -212,6 +218,16 @@ var formatOutputUInt = function (value) { return new BigNumber(value, 16); }; +/// @returns input bytes formatted to real +var formatOutputReal = function (value) { + return formatOutputInt(value).dividedBy(new BigNumber(2).pow(128)); +}; + +/// @returns input bytes formatted to ureal +var formatOutputUReal = function (value) { + return formatOutputUInt(value).dividedBy(new BigNumber(2).pow(128)); +}; + /// @returns right-aligned input bytes formatted to hex var formatOutputHash = function (value) { return "0x" + value; @@ -247,8 +263,8 @@ var setupOutputTypes = function () { { type: prefixedType('int'), format: formatOutputInt }, { type: prefixedType('hash'), format: formatOutputHash }, { type: prefixedType('string'), format: formatOutputString }, - { type: prefixedType('real'), format: formatOutputInt }, - { type: prefixedType('ureal'), format: formatOutputInt }, + { type: prefixedType('real'), format: formatOutputReal }, + { type: prefixedType('ureal'), format: formatOutputUReal }, { type: namedType('address'), format: formatOutputAddress }, { type: namedType('bool'), format: formatOutputBool } ]; |