Merge pull request #202 from cubedro/develop
Added external api for best block
This commit is contained in:
commit
c0b5ffc5e1
11
app.js
11
app.js
@ -43,9 +43,18 @@ client = new Primus(server, {
|
|||||||
client.use('emit', require('primus-emit'));
|
client.use('emit', require('primus-emit'));
|
||||||
|
|
||||||
|
|
||||||
|
// Init external API
|
||||||
|
external = new Primus(server, {
|
||||||
|
transformer: 'websockets',
|
||||||
|
pathname: '/external',
|
||||||
|
parser: 'JSON'
|
||||||
|
});
|
||||||
|
|
||||||
|
external.use('emit', require('primus-emit'));
|
||||||
|
|
||||||
// Init collections
|
// Init collections
|
||||||
var Collection = require('./lib/collection');
|
var Collection = require('./lib/collection');
|
||||||
var Nodes = new Collection();
|
var Nodes = new Collection(external);
|
||||||
|
|
||||||
Nodes.setChartsCallback(function (err, charts)
|
Nodes.setChartsCallback(function (err, charts)
|
||||||
{
|
{
|
||||||
|
@ -2,13 +2,15 @@ var _ = require('lodash');
|
|||||||
var Blockchain = require('./history');
|
var Blockchain = require('./history');
|
||||||
var Node = require('./node');
|
var Node = require('./node');
|
||||||
|
|
||||||
var Collection = function Collection()
|
var Collection = function Collection(externalAPI)
|
||||||
{
|
{
|
||||||
this._items = [];
|
this._items = [];
|
||||||
this._blockchain = new Blockchain();
|
this._blockchain = new Blockchain();
|
||||||
this._askedForHistory = false;
|
this._askedForHistory = false;
|
||||||
this._askedForHistoryTime = 0;
|
this._askedForHistoryTime = 0;
|
||||||
this._debounced = null;
|
this._debounced = null;
|
||||||
|
this._externalAPI = externalAPI;
|
||||||
|
this._highestBlock = 0;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -76,6 +78,15 @@ Collection.prototype.addBlock = function(id, stats, callback)
|
|||||||
stats.received = block.block.received;
|
stats.received = block.block.received;
|
||||||
stats.propagation = block.block.propagation;
|
stats.propagation = block.block.propagation;
|
||||||
|
|
||||||
|
if(block.block.number > this._highestBlock)
|
||||||
|
{
|
||||||
|
this._highestBlock = block.block.number;
|
||||||
|
this._externalAPI.write({
|
||||||
|
action:"bestBlock",
|
||||||
|
number: this._highestBlock
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
node.setBlock(stats, propagationHistory, callback);
|
node.setBlock(stats, propagationHistory, callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user