From 86b417e83f1f631cd55d16596b458b74601c43e5 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 19 Jan 2015 11:36:41 +0100 Subject: fixes for autoprovider --- lib/autoprovider.js | 5 ++--- lib/providermanager.js | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/autoprovider.js b/lib/autoprovider.js index a2c265ccb..0501b93d8 100644 --- a/lib/autoprovider.js +++ b/lib/autoprovider.js @@ -27,10 +27,9 @@ * if it fails, it uses HttpRpcProvider */ -// TODO: is these line is supposed to be here? +var web3 = require('./web3'); // jshint ignore:line if (process.env.NODE_ENV !== 'build') { var WebSocket = require('ws'); // jshint ignore:line - var web3 = require('./web3'); // jshint ignore:line } /** @@ -73,7 +72,7 @@ var AutoProvider = function (userOptions) { self.poll = self.provider.poll.bind(self.provider); } self.sendQueue.forEach(function (payload) { - self.provider(payload); + self.provider.send(payload); }); self.onmessageQueue.forEach(function (handler) { self.provider.onmessage = handler; diff --git a/lib/providermanager.js b/lib/providermanager.js index 2697ebbd7..f79a9b087 100644 --- a/lib/providermanager.js +++ b/lib/providermanager.js @@ -23,7 +23,6 @@ * @date 2014 */ -// TODO: is these line is supposed to be here? var web3 = require('./web3'); // jshint ignore:line /** -- cgit v1.2.3 From af54832d2435ff4116c887effa09e4f276ac970c Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 19 Jan 2015 12:59:29 +0100 Subject: encoding real on input --- lib/abi.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/abi.js b/lib/abi.js index 319b06066..0b0049ea5 100644 --- a/lib/abi.js +++ b/lib/abi.js @@ -116,6 +116,13 @@ var formatInputBool = function (value) { return '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0'); }; +/// Formats input value to byte representation of real +/// Values are multiplied by 2^m and encoded as integers +/// @returns byte representation of real +var formatInputReal = function (value) { + return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128))); +}; + var dynamicTypeBytes = function (type, value) { // TODO: decide what to do with array of strings if (arrayType(type) || prefixedType('string')(type)) @@ -132,8 +139,8 @@ var setupInputTypes = function () { { type: prefixedType('int'), format: formatInputInt }, { type: prefixedType('hash'), format: formatInputInt }, { type: prefixedType('string'), format: formatInputString }, - { type: prefixedType('real'), format: formatInputInt }, - { type: prefixedType('ureal'), format: formatInputInt }, + { type: prefixedType('real'), format: formatInputReal }, + { type: prefixedType('ureal'), format: formatInputReal }, { type: namedType('address'), format: formatInputInt }, { type: namedType('bool'), format: formatInputBool } ]; -- cgit v1.2.3 From 6a58db66f7f42a49667bcc751418256441752279 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 19 Jan 2015 13:22:58 +0100 Subject: parsing real, ureal values on output --- lib/abi.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/abi.js b/lib/abi.js index 0b0049ea5..72001eaa0 100644 --- a/lib/abi.js +++ b/lib/abi.js @@ -193,13 +193,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); @@ -211,6 +217,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; @@ -246,8 +262,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 } ]; -- cgit v1.2.3