diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-31 22:22:05 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-31 22:22:05 +0800 |
commit | b20e972bec52781de806fb050e72d44b729c6541 (patch) | |
tree | 0d8114da1536ae5ec6c2c606a30e1ae4c2cb311f /lib/utils.js | |
parent | a8a2e3231c2ced50989dc5d23659f7482a667f69 (diff) | |
download | dexon-b20e972bec52781de806fb050e72d44b729c6541.tar dexon-b20e972bec52781de806fb050e72d44b729c6541.tar.gz dexon-b20e972bec52781de806fb050e72d44b729c6541.tar.bz2 dexon-b20e972bec52781de806fb050e72d44b729c6541.tar.lz dexon-b20e972bec52781de806fb050e72d44b729c6541.tar.xz dexon-b20e972bec52781de806fb050e72d44b729c6541.tar.zst dexon-b20e972bec52781de806fb050e72d44b729c6541.zip |
few methods moved to utils
Diffstat (limited to 'lib/utils.js')
-rw-r--r-- | lib/utils.js | 34 |
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 }; |