From 80c97ca21b168e7f94cae6333be5439b6db2fe1d Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sat, 31 Jan 2015 03:42:13 +0100 Subject: events --- lib/event.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'lib/event.js') diff --git a/lib/event.js b/lib/event.js index c01fea6ef..efb85b1fc 100644 --- a/lib/event.js +++ b/lib/event.js @@ -25,27 +25,36 @@ var utils = require('./utils'); var inputWithName = function (inputs, name) { var index = utils.findIndex(inputs, function (input) { - return input.name === name; + return input.name === name; }); + if (index === -1) { - console.error('indexed param ' + name + ' not found in the abi'); - return undefined; + console.error('indexed paray with name ' + name + ' not found'); + return undefined; } return inputs[index]; }; -var indexedParamsToTopics = function (inputs, indexed) { - Object.keys(indexed).map(function (key) { - var inp = inputWithName(key); +var indexedParamsToTopics = function (event, indexed) { + // sort keys? + return Object.keys(indexed).map(function (key) { + // TODO: simplify this! + var parser = abi.inputParser([{ + name: 'test', + inputs: [inputWithName(event.inputs, key)] + }]); + var value = indexed[key]; if (value instanceof Array) { - + return value.map(function (v) { + return parser.test(v); + }); } + return parser.test(value); }); }; var implementationOfEvent = function (address, signature, event) { - // valid options are 'earliest', 'latest', 'offset' and 'max', as defined for 'eth.watch' return function (indexed, options) { @@ -53,6 +62,9 @@ var implementationOfEvent = function (address, signature, event) { o.address = address; o.topic = []; o.topic.push(signature); + if (indexed) { + o.topic = o.topic.concat(indexedParamsToTopics(event, indexed)); + } return o; }; }; -- cgit