diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-31 08:30:19 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-31 08:30:19 +0800 |
commit | 995861de4d61ffae9e60ae3fc08b2775b2e81f7b (patch) | |
tree | 74fa44db33570dbccb8f0265f8e9bccd87592936 /lib | |
parent | 600c9dd27dde3269a1682b875f82d3db46cee2c9 (diff) | |
download | dexon-995861de4d61ffae9e60ae3fc08b2775b2e81f7b.tar dexon-995861de4d61ffae9e60ae3fc08b2775b2e81f7b.tar.gz dexon-995861de4d61ffae9e60ae3fc08b2775b2e81f7b.tar.bz2 dexon-995861de4d61ffae9e60ae3fc08b2775b2e81f7b.tar.lz dexon-995861de4d61ffae9e60ae3fc08b2775b2e81f7b.tar.xz dexon-995861de4d61ffae9e60ae3fc08b2775b2e81f7b.tar.zst dexon-995861de4d61ffae9e60ae3fc08b2775b2e81f7b.zip |
event options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/contract.js | 4 | ||||
-rw-r--r-- | lib/event.js | 11 | ||||
-rw-r--r-- | lib/filter.js | 17 | ||||
-rw-r--r-- | lib/web3.js | 14 |
4 files changed, 33 insertions, 13 deletions
diff --git a/lib/contract.js b/lib/contract.js index eff16cca4..6056581d4 100644 --- a/lib/contract.js +++ b/lib/contract.js @@ -131,7 +131,11 @@ var addEventsToContract = function (contract, desc, address) { var o = event.apply(null, params); return web3.eth.watch(o); }; + + // this property should be used by eth.filter to check if object is an event + impl._isEvent = true; + // TODO: we can remove address && topic properties, they are not used anymore since we introduced _isEvent impl.address = address; Object.defineProperty(impl, 'topic', { 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; }; }; diff --git a/lib/filter.js b/lib/filter.js index 39309fb27..d97276f78 100644 --- a/lib/filter.js +++ b/lib/filter.js @@ -27,16 +27,19 @@ var web3 = require('./web3'); // jshint ignore:line /// should be used when we want to watch something /// it's using inner polling mechanism and is notified about changes -var Filter = function(options, impl) { - this.impl = impl; - this.callbacks = []; +/// TODO: change 'options' name cause it may be not the best matching one, since we have events +var Filter = function(options, indexed, impl) { - if (typeof options !== "string") { - // evaluate lazy properties + if (options._isEvent) { + return options(indexed); + } else if (typeof options !== "string") { + + // topics property is deprecated, warn about it! if (options.topics) { console.warn('"topics" is deprecated, use "topic" instead'); } + // evaluate lazy properties options = { to: options.to, topic: options.topic, @@ -46,7 +49,11 @@ var Filter = function(options, impl) { skip: options.skip, address: options.address }; + } + + this.impl = impl; + this.callbacks = []; this.id = impl.newFilter(options); web3.provider.startPolling({call: impl.changed, args: [this.id]}, this.id, this.trigger.bind(this)); diff --git a/lib/web3.js b/lib/web3.js index 7b8bbd28a..6bf8f7bc0 100644 --- a/lib/web3.js +++ b/lib/web3.js @@ -278,8 +278,11 @@ var web3 = { return ret; }; }, - watch: function (params) { - return new web3.filter(params, ethWatch); + + /// @param filter may be a string, object or event + /// @param indexed is optional, this may be an object with optional event indexed params + watch: function (filter, indexed) { + return new web3.filter(filter, indexed, ethWatch); } }, @@ -288,8 +291,11 @@ var web3 = { /// shh object prototype shh: { - watch: function (params) { - return new web3.filter(params, shhWatch); + + /// @param filter may be a string, object or event + /// @param indexed is optional, this may be an object with optional event indexed params + watch: function (filter, indexed) { + return new web3.filter(filter, indexed, shhWatch); } }, |