diff --git a/lib/web3/filter.js b/lib/web3/filter.js index d781291..d94d7e2 100644 --- a/lib/web3/filter.js +++ b/lib/web3/filter.js @@ -24,7 +24,6 @@ * @date 2014 */ -var RequestManager = require('./requestmanager'); var formatters = require('./formatters'); var utils = require('../utils/utils'); @@ -124,19 +123,21 @@ var pollFilter = function(self) { } }; - RequestManager.getInstance().startPolling({ + self.requestManager.startPolling({ method: self.implementation.poll.call, params: [self.filterId], }, self.filterId, onMessage, self.stopWatching.bind(self)); }; -var Filter = function (options, methods, formatter, callback) { +var Filter = function (web3, options, methods, formatter, callback) { var self = this; var implementation = {}; methods.forEach(function (method) { method.attachToObject(implementation); + method.setRequestManager(web3._requestManager); }); + this.requestManager = web3._requestManager; this.options = getOptions(options); this.implementation = implementation; this.filterId = null; @@ -188,7 +189,7 @@ Filter.prototype.watch = function (callback) { }; Filter.prototype.stopWatching = function () { - RequestManager.getInstance().stopPolling(this.filterId); + this.requestManager.stopPolling(this.filterId); // remove filter async this.implementation.uninstallFilter(this.filterId, function(){}); this.callbacks = []; diff --git a/lib/web3/method.js b/lib/web3/method.js index 8d72d0d..73cad60 100644 --- a/lib/web3/method.js +++ b/lib/web3/method.js @@ -123,7 +123,7 @@ Method.prototype.toPayload = function (args) { Method.prototype.attachToObject = function (obj) { var func = this.buildCall(); -// func.call = this.call; // that's ugly. filter.js uses it + func.call = this.call; // TODO!!! that's ugly. filter.js uses it var name = this.name.split('.'); if (name.length > 1) { obj[name[0]] = obj[name[0]] || {}; diff --git a/lib/web3/methods/eth.js b/lib/web3/methods/eth.js index 0c06460..603840d 100644 --- a/lib/web3/methods/eth.js +++ b/lib/web3/methods/eth.js @@ -29,6 +29,8 @@ var Method = require('../method'); var Property = require('../property'); var c = require('../../utils/config'); var Contract = require('../contract'); +var watches = require('./watches'); +var Filter = require('../filter'); var blockCall = function (args) { return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber"; @@ -305,5 +307,9 @@ Eth.prototype.contract = function (abi) { return factory; }; +Eth.prototype.filter = function (fil, callback) { + return new Filter(this.web3, fil, watches.eth(), formatters.outputLogFormatter, callback); +}; + module.exports = Eth; diff --git a/test/polling.js b/test/polling.js index 9d01d00..2173e16 100644 --- a/test/polling.js +++ b/test/polling.js @@ -1,6 +1,7 @@ var chai = require('chai'); var assert = chai.assert; -var web3 = require('../index'); +var Web3 = require('../index'); +var web3 = new Web3(); var FakeHttpProvider = require('./helpers/FakeHttpProvider'); var utils = require('../lib/utils/utils'); @@ -31,7 +32,6 @@ var tests = [{ } }]; -/* var testPolling = function (tests) { describe('web3.eth.filter.polling', function () { @@ -60,7 +60,7 @@ var testPolling = function (tests) { }); // when - var filter = web3[test.protocol].filter.apply(null, test.args); + var filter = web3[test.protocol].filter.apply(web3[test.protocol], test.args); provider.injectBatchResults([test.secondResult]); filter.watch(function (err, result) { if (test.err) { @@ -109,7 +109,7 @@ var testPolling = function (tests) { }); // when - var filter = web3[test.protocol].filter.apply(null, test.args); + var filter = web3[test.protocol].filter.apply(web3[test.protocol], test.args); provider.injectBatchResults([test.secondResult]); }); }); @@ -117,5 +117,3 @@ var testPolling = function (tests) { }; testPolling(tests); - -*/