From 995861de4d61ffae9e60ae3fc08b2775b2e81f7b Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sat, 31 Jan 2015 01:30:19 +0100 Subject: event options --- lib/event.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/event.js') diff --git a/lib/event.js b/lib/event.js index ae2195381..ea5f5b71e 100644 --- a/lib/event.js +++ b/lib/event.js @@ -20,13 +20,16 @@ * @date 2014 */ +var abi = require('./abi'); + var implementationOfEvent = function (address, signature) { - 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); return o; }; }; -- cgit v1.2.3 From 2491c99b37241b8770bca516d5641b2d00a7a660 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sat, 31 Jan 2015 02:54:17 +0100 Subject: abi.js cleanup && new types.js, utils.js --- lib/event.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'lib/event.js') diff --git a/lib/event.js b/lib/event.js index ea5f5b71e..c01fea6ef 100644 --- a/lib/event.js +++ b/lib/event.js @@ -21,8 +21,31 @@ */ 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 ' + name + ' not found in the abi'); + return undefined; + } + return inputs[index]; +}; + +var indexedParamsToTopics = function (inputs, indexed) { + Object.keys(indexed).map(function (key) { + var inp = inputWithName(key); + var value = indexed[key]; + if (value instanceof Array) { + + } + }); +}; + +var implementationOfEvent = function (address, signature, event) { -var implementationOfEvent = function (address, signature) { // valid options are 'earliest', 'latest', 'offset' and 'max', as defined for 'eth.watch' return function (indexed, options) { -- cgit v1.2.3 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 v1.2.3 From b20e972bec52781de806fb050e72d44b729c6541 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sat, 31 Jan 2015 15:22:05 +0100 Subject: few methods moved to utils --- lib/event.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/event.js') diff --git a/lib/event.js b/lib/event.js index efb85b1fc..43ea96d12 100644 --- a/lib/event.js +++ b/lib/event.js @@ -29,7 +29,7 @@ var inputWithName = function (inputs, name) { }); if (index === -1) { - console.error('indexed paray with name ' + name + ' not found'); + console.error('indexed param with name ' + name + ' not found'); return undefined; } return inputs[index]; -- cgit v1.2.3 From 589c4fb30f2e68972b898c5ce084cda5b0831266 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sat, 31 Jan 2015 15:48:49 +0100 Subject: formatInput && formatOutput simplified --- lib/event.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'lib/event.js') diff --git a/lib/event.js b/lib/event.js index 43ea96d12..812ef9115 100644 --- a/lib/event.js +++ b/lib/event.js @@ -38,19 +38,15 @@ var inputWithName = function (inputs, name) { 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 inputs = [inputWithName(event.inputs, key)]; var value = indexed[key]; if (value instanceof Array) { return value.map(function (v) { - return parser.test(v); + return abi.formatInput(inputs, [v]); }); } - return parser.test(value); + return abi.formatInput(inputs, [value]); }); }; -- cgit v1.2.3