aboutsummaryrefslogtreecommitdiffstats
path: root/lib/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js34
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/utils.js b/lib/utils.js
index f9fcd3389..5cd6ec8d6 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -72,10 +72,42 @@ var fromAscii = function(str, pad) {
return "0x" + hex;
};
+/// @returns display name for function/event eg. multiply(uint256) -> multiply
+var extractDisplayName = function (name) {
+ var length = name.indexOf('(');
+ return length !== -1 ? name.substr(0, length) : name;
+};
+
+/// @returns overloaded part of function/event name
+var extractTypeName = function (name) {
+ /// TODO: make it invulnerable
+ var length = name.indexOf('(');
+ return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)) : "";
+};
+
+/// 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';
+ });
+};
module.exports = {
findIndex: findIndex,
toAscii: toAscii,
- fromAscii: fromAscii
+ fromAscii: fromAscii,
+ extractDisplayName: extractDisplayName,
+ extractTypeName: extractTypeName,
+ filterFunctions: filterFunctions,
+ filterEvents: filterEvents
};