eth.filter works

This commit is contained in:
debris 2015-10-08 07:42:08 +02:00
parent 9da9bfdbd4
commit 190f9815d9
4 changed files with 16 additions and 11 deletions

View File

@ -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 = [];

View File

@ -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]] || {};

View File

@ -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;

View File

@ -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);
*/