Commit 61e8ae2f authored by Marek Kotewicz's avatar Marek Kotewicz

events init

parent 2544d2c9
...@@ -74,6 +74,14 @@ var filterFunctions = function (json) { ...@@ -74,6 +74,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 string string to be padded
/// @param number of characters that result string should have /// @param number of characters that result string should have
/// @param sign, by default 0 /// @param sign, by default 0
...@@ -415,7 +423,8 @@ module.exports = { ...@@ -415,7 +423,8 @@ module.exports = {
methodDisplayName: methodDisplayName, methodDisplayName: methodDisplayName,
methodTypeName: methodTypeName, methodTypeName: methodTypeName,
getMethodWithName: getMethodWithName, getMethodWithName: getMethodWithName,
filterFunctions: filterFunctions filterFunctions: filterFunctions,
filterEvents: filterEvents
}; };
...@@ -507,6 +516,7 @@ var contract = function (address, desc) { ...@@ -507,6 +516,7 @@ var contract = function (address, desc) {
}); });
// create contract functions
abi.filterFunctions(desc).forEach(function (method) { abi.filterFunctions(desc).forEach(function (method) {
var displayName = abi.methodDisplayName(method.name); var displayName = abi.methodDisplayName(method.name);
...@@ -561,6 +571,31 @@ var contract = function (address, desc) { ...@@ -561,6 +571,31 @@ var contract = function (address, desc) {
}); });
// create contract events
abi.filterEvents(desc).forEach(function (event) {
// TODO: rename these methods, cause they are used not only for methods
var displayName = abi.methodDisplayName(event.name);
var typeName = abi.methodTypeName(event.name);
var impl = function (options) {
var o = options || {};
o.address = o.address || address;
o.topics = o.topics || [];
o.topics.push(abi.methodSignature(event.name));
return web3.eth.watch(o);
};
if (result[displayName] === undefined) {
result[displayName] = impl;
}
result[displayName][typeName] = impl;
});
return result; return result;
}; };
......
This diff is collapsed.
This diff is collapsed.
...@@ -85,6 +85,7 @@ var contract = function (address, desc) { ...@@ -85,6 +85,7 @@ var contract = function (address, desc) {
}); });
// create contract functions
abi.filterFunctions(desc).forEach(function (method) { abi.filterFunctions(desc).forEach(function (method) {
var displayName = abi.methodDisplayName(method.name); var displayName = abi.methodDisplayName(method.name);
...@@ -139,6 +140,31 @@ var contract = function (address, desc) { ...@@ -139,6 +140,31 @@ var contract = function (address, desc) {
}); });
// create contract events
abi.filterEvents(desc).forEach(function (event) {
// TODO: rename these methods, cause they are used not only for methods
var displayName = abi.methodDisplayName(event.name);
var typeName = abi.methodTypeName(event.name);
var impl = function (options) {
var o = options || {};
o.address = o.address || address;
o.topics = o.topics || [];
o.topics.push(abi.methodSignature(event.name));
return web3.eth.watch(o);
};
if (result[displayName] === undefined) {
result[displayName] = impl;
}
result[displayName][typeName] = impl;
});
return result; return result;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment