aboutsummaryrefslogtreecommitdiffstats
path: root/lib/event.js
diff options
context:
space:
mode:
authorMarek Kotewicz <marek.kotewicz@gmail.com>2015-01-31 23:02:16 +0800
committerMarek Kotewicz <marek.kotewicz@gmail.com>2015-01-31 23:02:16 +0800
commit3cdf108057a6f0ce83bb3eb9d9b2804ae07956ca (patch)
tree11fc98b4f70b0f5b549cc463bb97f3a15764dae2 /lib/event.js
parent2eedc330bfcb976b8eef2b6aee69e19430de1713 (diff)
parent688030ecb615cbf97c428cf1dd2e337380079168 (diff)
downloaddexon-3cdf108057a6f0ce83bb3eb9d9b2804ae07956ca.tar
dexon-3cdf108057a6f0ce83bb3eb9d9b2804ae07956ca.tar.gz
dexon-3cdf108057a6f0ce83bb3eb9d9b2804ae07956ca.tar.bz2
dexon-3cdf108057a6f0ce83bb3eb9d9b2804ae07956ca.tar.lz
dexon-3cdf108057a6f0ce83bb3eb9d9b2804ae07956ca.tar.xz
dexon-3cdf108057a6f0ce83bb3eb9d9b2804ae07956ca.tar.zst
dexon-3cdf108057a6f0ce83bb3eb9d9b2804ae07956ca.zip
Merge branch 'develop'
Diffstat (limited to 'lib/event.js')
-rw-r--r--lib/event.js44
1 files changed, 39 insertions, 5 deletions
diff --git a/lib/event.js b/lib/event.js
index ae2195381..812ef9115 100644
--- a/lib/event.js
+++ b/lib/event.js
@@ -20,13 +20,47 @@
* @date 2014
*/
-var implementationOfEvent = function (address, signature) {
+var abi = require('./abi');
+var utils = require('./utils');
+
+var inputWithName = function (inputs, name) {
+ var index = utils.findIndex(inputs, function (input) {
+ return input.name === name;
+ });
+
+ if (index === -1) {
+ console.error('indexed param with name ' + name + ' not found');
+ return undefined;
+ }
+ return inputs[index];
+};
+
+var indexedParamsToTopics = function (event, indexed) {
+ // sort keys?
+ return Object.keys(indexed).map(function (key) {
+ var inputs = [inputWithName(event.inputs, key)];
+
+ var value = indexed[key];
+ if (value instanceof Array) {
+ return value.map(function (v) {
+ return abi.formatInput(inputs, [v]);
+ });
+ }
+ return abi.formatInput(inputs, [value]);
+ });
+};
+
+var implementationOfEvent = function (address, signature, event) {
- return function (options) {
+ // valid options are 'earliest', 'latest', 'offset' and 'max', as defined for 'eth.watch'
+ return function (indexed, options) {
var o = options || {};
- o.address = o.address || address;
- o.topics = o.topics || [];
- o.topics.push(signature);
+ o.address = address;
+ o.topic = [];
+ o.topic.push(signature);
+ if (indexed) {
+ o.topic = o.topic.concat(indexedParamsToTopics(event, indexed));
+ }
return o;
};
};