From 09f633596da91818201781cc009e1e1ab6f8d059 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 27 Jan 2015 15:20:22 +0100 Subject: fixed #23 --- lib/abi.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/abi.js') diff --git a/lib/abi.js b/lib/abi.js index 0989f4e15..ba47dca73 100644 --- a/lib/abi.js +++ b/lib/abi.js @@ -211,6 +211,7 @@ var signedIsNegative = function (value) { /// Formats input right-aligned input bytes to int /// @returns right-aligned input bytes formatted to int var formatOutputInt = function (value) { + value = value || "0"; // check if it's negative number // it it is, return two's complement if (signedIsNegative(value)) { @@ -222,6 +223,7 @@ var formatOutputInt = function (value) { /// Formats big right-aligned input bytes to uint /// @returns right-aligned input bytes formatted to uint var formatOutputUInt = function (value) { + value = value || "0"; return new BigNumber(value, 16); }; -- cgit v1.2.3 From ea7c2fc673db31f96583e4712aa0fb78f5d709eb Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 28 Jan 2015 14:20:36 +0100 Subject: abi function type --- lib/abi.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'lib/abi.js') diff --git a/lib/abi.js b/lib/abi.js index ba47dca73..a0752647f 100644 --- a/lib/abi.js +++ b/lib/abi.js @@ -65,6 +65,14 @@ var getMethodWithName = function (json, methodName) { return json[index]; }; +/// Filters all function from input abi +/// @returns abi array with filtered objects of type 'function' +var filterFunctions = function (json) { + return json.filter(function (current) { + return current.type === 'function'; + }); +}; + /// @param string string to be padded /// @param number of characters that result string should have /// @param sign, by default 0 @@ -351,7 +359,7 @@ var methodTypeName = function (method) { /// @returns input parser object for given json abi var inputParser = function (json) { var parser = {}; - json.forEach(function (method) { + filterFunctions(json).forEach(function (method) { var displayName = methodDisplayName(method.name); var typeName = methodTypeName(method.name); @@ -374,7 +382,7 @@ var inputParser = function (json) { /// @returns output parser for given json abi var outputParser = function (json) { var parser = {}; - json.forEach(function (method) { + filterFunctions(json).forEach(function (method) { var displayName = methodDisplayName(method.name); var typeName = methodTypeName(method.name); @@ -405,6 +413,7 @@ module.exports = { methodSignature: methodSignature, methodDisplayName: methodDisplayName, methodTypeName: methodTypeName, - getMethodWithName: getMethodWithName + getMethodWithName: getMethodWithName, + filterFunctions: filterFunctions }; -- cgit v1.2.3 From 2544d2c952dc003d62bdb99a554b3fa576b202c5 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 28 Jan 2015 14:39:10 +0100 Subject: tests for abi.filters --- lib/abi.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/abi.js') diff --git a/lib/abi.js b/lib/abi.js index a0752647f..a0c862593 100644 --- a/lib/abi.js +++ b/lib/abi.js @@ -73,6 +73,14 @@ var filterFunctions = function (json) { }); }; +/// Filters all events form input abi +/// @returns abi array with filtered objects of type 'event' +var filterEvents = function (json) { + return json.filter(function (current) { + return current.type === 'event'; + }); +}; + /// @param string string to be padded /// @param number of characters that result string should have /// @param sign, by default 0 @@ -414,6 +422,7 @@ module.exports = { methodDisplayName: methodDisplayName, methodTypeName: methodTypeName, getMethodWithName: getMethodWithName, - filterFunctions: filterFunctions + filterFunctions: filterFunctions, + filterEvents: filterEvents }; -- cgit v1.2.3