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/abi.js') 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