Merge pull request #161 from cubedro/develop

Fixes and improvements
This commit is contained in:
Marian OANCΞA 2015-06-02 01:00:01 +03:00
commit b4d21223c4

View File

@ -105,6 +105,7 @@ function Node ()
this._socket = false; this._socket = false;
this._latestQueue = null; this._latestQueue = null;
this._chainDebouncer = 0;
this.pendingFilter = false; this.pendingFilter = false;
this.chainFilter = false; this.chainFilter = false;
this.updateInterval = false; this.updateInterval = false;
@ -233,6 +234,7 @@ Node.prototype.setupSockets = function()
}) })
.on('timeout', function () .on('timeout', function ()
{ {
self._socket = false;
console.error('wsc', 'Socket connection timeout'); console.error('wsc', 'Socket connection timeout');
}) })
.on('close', function () .on('close', function ()
@ -247,6 +249,7 @@ Node.prototype.setupSockets = function()
}) })
.on('online', function () .on('online', function ()
{ {
self._socket = true;
console.info('wsc', 'Network connection is online'); console.info('wsc', 'Network connection is online');
}) })
.on('reconnect', function () .on('reconnect', function ()
@ -255,19 +258,23 @@ Node.prototype.setupSockets = function()
}) })
.on('reconnect scheduled', function (opts) .on('reconnect scheduled', function (opts)
{ {
self._socket = false;
console.warn('wsc', 'Reconnecting in', opts.scheduled, 'ms'); console.warn('wsc', 'Reconnecting in', opts.scheduled, 'ms');
console.warn('wsc', 'This is attempt', opts.attempt, 'out of', opts.retries); console.warn('wsc', 'This is attempt', opts.attempt, 'out of', opts.retries);
}) })
.on('reconnected', function (opts) .on('reconnected', function (opts)
{ {
self._socket = true;
console.success('wsc', 'Socket reconnected successfully after', opts.duration, 'ms'); console.success('wsc', 'Socket reconnected successfully after', opts.duration, 'ms');
}) })
.on('reconnect timeout', function (err, opts) .on('reconnect timeout', function (err, opts)
{ {
self._socket = false;
console.error('wsc', 'Socket reconnect atempt took too long:', err.message); console.error('wsc', 'Socket reconnect atempt took too long:', err.message);
}) })
.on('reconnect failed', function (err, opts) .on('reconnect failed', function (err, opts)
{ {
self._socket = false;
console.error('wsc', 'Socket reconnect failed:', err.message); console.error('wsc', 'Socket reconnect failed:', err.message);
}); });
} }
@ -388,7 +395,12 @@ Node.prototype.validateLatestBlock = function (error, result, timeString)
{ {
console.warn("==>", "Got same block:", chalk.reset.cyan(block.number)); console.warn("==>", "Got same block:", chalk.reset.cyan(block.number));
return false; if( _.isEqual(JSON.stringify(this.stats.block), JSON.stringify(block)) )
return false;
console.info(this.stats.block);
console.info(block);
console.warn("Blocks are different... updating block");
} }
console.success("==>", "Got block:", chalk.reset.red(block.number)); console.success("==>", "Got block:", chalk.reset.red(block.number));
@ -655,7 +667,24 @@ Node.prototype.setWatches = function()
console.info('>>>', 'Chain Filter triggered: ', chalk.reset.red(hash), '- last trigger:', chalk.reset.cyan(time)); console.info('>>>', 'Chain Filter triggered: ', chalk.reset.red(hash), '- last trigger:', chalk.reset.cyan(time));
self._latestQueue.push(hash); if(time < 5)
{
self._chainDebouncer++;
} else {
self._chainDebouncer = 0;
}
if(self._chainDebouncer < 20)
{
self._latestQueue.push(hash);
}
else
{
debounce(function() {
self._latestQueue.push(hash);
self._chainDebouncer = 0;
}, 5);
}
}); });
console.success("Installed chain filter"); console.success("Installed chain filter");
@ -686,8 +715,9 @@ Node.prototype.setWatches = function()
self.getPending(); self.getPending();
}, 5); }, 5);
} }
console.success("Installed pending filter");
}); });
console.success("Installed pending filter");
} }
catch (err) catch (err)
{ {