aboutsummaryrefslogtreecommitdiffstats
path: root/lib/abi.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/abi.js')
-rw-r--r--lib/abi.js26
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/abi.js b/lib/abi.js
index 0989f4e15..a0c862593 100644
--- a/lib/abi.js
+++ b/lib/abi.js
@@ -65,6 +65,22 @@ 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';
+ });
+};
+
+/// 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
@@ -211,6 +227,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 +239,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);
};
@@ -349,7 +367,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);
@@ -372,7 +390,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);
@@ -403,6 +421,8 @@ module.exports = {
methodSignature: methodSignature,
methodDisplayName: methodDisplayName,
methodTypeName: methodTypeName,
- getMethodWithName: getMethodWithName
+ getMethodWithName: getMethodWithName,
+ filterFunctions: filterFunctions,
+ filterEvents: filterEvents
};