mirror of https://github.com/status-im/web3.js.git
fixed filter polling
This commit is contained in:
parent
df4e612278
commit
c8f8ba8086
|
@ -134,8 +134,8 @@ var Filter = function (web3, options, methods, formatter, callback) {
|
|||
var self = this;
|
||||
var implementation = {};
|
||||
methods.forEach(function (method) {
|
||||
method.attachToObject(implementation);
|
||||
method.setRequestManager(web3._requestManager);
|
||||
method.attachToObject(implementation);
|
||||
});
|
||||
this.requestManager = web3._requestManager;
|
||||
this.options = getOptions(options);
|
||||
|
|
|
@ -40,6 +40,8 @@ var RequestManager = function (provider) {
|
|||
this.polls = {};
|
||||
this.timeout = null;
|
||||
this.isPolling = false;
|
||||
|
||||
this.poll();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
* @date 2015
|
||||
*/
|
||||
|
||||
var Method = require('./method');
|
||||
var formatters = require('./formatters');
|
||||
var utils = require('../utils/utils');
|
||||
|
||||
|
@ -41,7 +40,7 @@ var pollSyncing = function(self) {
|
|||
}
|
||||
|
||||
if(utils.isObject(sync))
|
||||
sync = self.implementation.outputFormatter(sync);
|
||||
sync = formatters.outputSyncingFormatter(sync);
|
||||
|
||||
self.callbacks.forEach(function (callback) {
|
||||
if (lastSyncState !== sync) {
|
||||
|
@ -60,8 +59,8 @@ var pollSyncing = function(self) {
|
|||
});
|
||||
};
|
||||
|
||||
self._web3._requestManager.startPolling({
|
||||
method: self.implementation.call,
|
||||
self.requestManager.startPolling({
|
||||
method: 'eth_syncing',
|
||||
params: [],
|
||||
}, self.pollId, onMessage, self.stopWatching.bind(self));
|
||||
|
||||
|
@ -69,15 +68,9 @@ var pollSyncing = function(self) {
|
|||
|
||||
var IsSyncing = function (web3, callback) {
|
||||
this._web3 = web3;
|
||||
this.requestManager = web3._requestManager;
|
||||
this.pollId = 'syncPoll_'+ Math.floor(Math.random() * 1000);
|
||||
this.callbacks = [];
|
||||
this.implementation = new Method({
|
||||
name: 'isSyncing',
|
||||
call: 'eth_syncing',
|
||||
params: 0,
|
||||
outputFormatter: formatters.outputSyncingFormatter
|
||||
});
|
||||
|
||||
this.addCallback(callback);
|
||||
pollSyncing(this);
|
||||
|
||||
|
|
|
@ -22,40 +22,40 @@ var tests = [{
|
|||
call: 'eth_syncing'
|
||||
}];
|
||||
|
||||
//describe('eth', function () {
|
||||
//describe(method, function () {
|
||||
//tests.forEach(function (test, index) {
|
||||
//it('property test: ' + index, function (done) {
|
||||
describe('eth', function () {
|
||||
describe(method, function () {
|
||||
tests.forEach(function (test, index) {
|
||||
it('property test: ' + index, function (done) {
|
||||
|
||||
// given
|
||||
var provider = new FakeHttpProvider();
|
||||
web3.setProvider(provider);
|
||||
web3.reset();
|
||||
provider.injectBatchResults(test.result);
|
||||
provider.injectValidation(function(payload) {
|
||||
assert.equal(payload[0].jsonrpc, '2.0', 'failed');
|
||||
assert.equal(payload[0].method, test.call);
|
||||
assert.deepEqual(payload[0].params, test.formattedArgs);
|
||||
});
|
||||
|
||||
var count = 1;
|
||||
|
||||
// TODO results seem to be overwritten
|
||||
|
||||
// call
|
||||
var syncing = web3.eth[method](function(e, res){
|
||||
if(count === 1) {
|
||||
assert.isTrue(res);
|
||||
count++;
|
||||
} else {
|
||||
assert.deepEqual(res, test.formattedResult);
|
||||
syncing.stopWatching();
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
//// given
|
||||
//var provider = new FakeHttpProvider();
|
||||
//web3.setProvider(provider);
|
||||
//web3.reset();
|
||||
//provider.injectBatchResults(test.result);
|
||||
//provider.injectValidation(function (payload) {
|
||||
//assert.equal(payload[0].jsonrpc, '2.0');
|
||||
//assert.equal(payload[0].method, test.call);
|
||||
//assert.deepEqual(payload[0].params, test.formattedArgs);
|
||||
//});
|
||||
|
||||
//var count = 1;
|
||||
|
||||
//// TODO results seem to be overwritten
|
||||
|
||||
//// call
|
||||
//var syncing = web3.eth[method](function(e, res){
|
||||
//if(count === 1) {
|
||||
//assert.isTrue(res);
|
||||
//count++;
|
||||
//} else {
|
||||
//assert.deepEqual(res, test.formattedResult);
|
||||
//syncing.stopWatching();
|
||||
//done();
|
||||
//}
|
||||
//});
|
||||
|
||||
//});
|
||||
//});
|
||||
//});
|
||||
//});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue