few methods moved to utils
This commit is contained in:
51
lib/abi.js
51
lib/abi.js
@ -27,22 +27,6 @@ var types = require('./types');
|
||||
var c = require('./const');
|
||||
var f = require('./formatters');
|
||||
|
||||
/// 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';
|
||||
});
|
||||
};
|
||||
|
||||
/// This method should be called if we want to check if givent type is an array type
|
||||
/// @returns true if it is, otherwise false
|
||||
var arrayType = function (type) {
|
||||
@ -154,27 +138,14 @@ var fromAbiOutput = function (method, output) {
|
||||
return result;
|
||||
};
|
||||
|
||||
/// @returns display name for method eg. multiply(uint256) -> multiply
|
||||
var methodDisplayName = function (method) {
|
||||
var length = method.indexOf('(');
|
||||
return length !== -1 ? method.substr(0, length) : method;
|
||||
};
|
||||
|
||||
/// @returns overloaded part of method's name
|
||||
var methodTypeName = function (method) {
|
||||
/// TODO: make it invulnerable
|
||||
var length = method.indexOf('(');
|
||||
return length !== -1 ? method.substr(length + 1, method.length - 1 - (length + 1)) : "";
|
||||
};
|
||||
|
||||
/// @param json abi for contract
|
||||
/// @returns input parser object for given json abi
|
||||
/// TODO: refactor creating the parser, do not double logic from contract
|
||||
var inputParser = function (json) {
|
||||
var parser = {};
|
||||
json.forEach(function (method) {
|
||||
var displayName = methodDisplayName(method.name);
|
||||
var typeName = methodTypeName(method.name);
|
||||
var displayName = utils.extractDisplayName(method.name);
|
||||
var typeName = utils.extractTypeName(method.name);
|
||||
|
||||
var impl = function () {
|
||||
var params = Array.prototype.slice.call(arguments);
|
||||
@ -197,8 +168,8 @@ var outputParser = function (json) {
|
||||
var parser = {};
|
||||
json.forEach(function (method) {
|
||||
|
||||
var displayName = methodDisplayName(method.name);
|
||||
var typeName = methodTypeName(method.name);
|
||||
var displayName = utils.extractDisplayName(method.name);
|
||||
var typeName = utils.extractTypeName(method.name);
|
||||
|
||||
var impl = function (output) {
|
||||
return fromAbiOutput(method, output);
|
||||
@ -214,19 +185,15 @@ var outputParser = function (json) {
|
||||
return parser;
|
||||
};
|
||||
|
||||
/// @param method name for which we want to get method signature
|
||||
/// @returns (promise) contract method signature for method with given name
|
||||
var methodSignature = function (name) {
|
||||
return web3.sha3(web3.fromAscii(name)).slice(0, 2 + c.ETH_METHOD_SIGNATURE_LENGTH * 2);
|
||||
/// @param function/event name for which we want to get signature
|
||||
/// @returns signature of function/event with given name
|
||||
var signatureFromAscii = function (name) {
|
||||
return web3.sha3(web3.fromAscii(name)).slice(0, 2 + c.ETH_SIGNATURE_LENGTH * 2);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputParser: inputParser,
|
||||
outputParser: outputParser,
|
||||
methodSignature: methodSignature,
|
||||
methodDisplayName: methodDisplayName,
|
||||
methodTypeName: methodTypeName,
|
||||
filterFunctions: filterFunctions,
|
||||
filterEvents: filterEvents
|
||||
signatureFromAscii: signatureFromAscii
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user