diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-19 20:22:58 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-19 20:22:58 +0800 |
commit | 6a58db66f7f42a49667bcc751418256441752279 (patch) | |
tree | 58f3e4b5ca956a1389324918d0d5695668720f94 /dist/ethereum.js | |
parent | af54832d2435ff4116c887effa09e4f276ac970c (diff) | |
download | go-tangerine-6a58db66f7f42a49667bcc751418256441752279.tar go-tangerine-6a58db66f7f42a49667bcc751418256441752279.tar.gz go-tangerine-6a58db66f7f42a49667bcc751418256441752279.tar.bz2 go-tangerine-6a58db66f7f42a49667bcc751418256441752279.tar.lz go-tangerine-6a58db66f7f42a49667bcc751418256441752279.tar.xz go-tangerine-6a58db66f7f42a49667bcc751418256441752279.tar.zst go-tangerine-6a58db66f7f42a49667bcc751418256441752279.zip |
parsing real, ureal values on output
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 } ]; |