Merge pull request #165 from cubedro/develop
AddBlock as a separate call
This commit is contained in:
commit
c758da2312
21
app.js
21
app.js
@ -144,6 +144,27 @@ api.on('connection', function(spark) {
|
||||
}
|
||||
});
|
||||
|
||||
spark.on('block', function(data)
|
||||
{
|
||||
if( !_.isUndefined(data.id) && !_.isUndefined(data.block) )
|
||||
{
|
||||
var stats = Nodes.addBlock(data.id, data.block);
|
||||
|
||||
if(stats !== false)
|
||||
{
|
||||
client.write({
|
||||
action: 'block',
|
||||
data: stats
|
||||
});
|
||||
|
||||
client.write({
|
||||
action: 'charts',
|
||||
data: Nodes.getCharts()
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
spark.on('pending', function(data)
|
||||
{
|
||||
if( !_.isUndefined(data.id) && !_.isUndefined(data.stats) )
|
||||
|
2
dist/js/netstats.min.js
vendored
2
dist/js/netstats.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/js/netstats.min.js.map
vendored
2
dist/js/netstats.min.js.map
vendored
File diff suppressed because one or more lines are too long
@ -39,6 +39,27 @@ Collection.prototype.update = function(id, stats)
|
||||
return node.setStats(stats, propagationHistory);
|
||||
}
|
||||
|
||||
Collection.prototype.addBlock = function(id, block)
|
||||
{
|
||||
var node = this.getNode({ id: id });
|
||||
|
||||
if (!node)
|
||||
return false;
|
||||
|
||||
var block = this._blockchain.add(block, id);
|
||||
|
||||
if (!block)
|
||||
return false;
|
||||
|
||||
var propagationHistory = this._blockchain.getNodePropagation(id);
|
||||
|
||||
block.arrived = block.arrived;
|
||||
block.received = block.received;
|
||||
block.propagation = block.propagation;
|
||||
|
||||
return node.setBlock(block, propagationHistory);
|
||||
}
|
||||
|
||||
Collection.prototype.updatePending = function(id, stats)
|
||||
{
|
||||
var node = this.getNode({ id: id });
|
||||
|
@ -141,6 +141,31 @@ Node.prototype.setStats = function(stats, history)
|
||||
return false;
|
||||
}
|
||||
|
||||
Node.prototype.setBlock = function(block, history)
|
||||
{
|
||||
if( !_.isUndefined(block) && !_.isUndefined(block.block.number) )
|
||||
{
|
||||
this.history = history;
|
||||
var propagationAvg = 0;
|
||||
|
||||
var positives = _.filter(history, function(p) {
|
||||
return p >= 0;
|
||||
});
|
||||
|
||||
if(positives.length > 0)
|
||||
propagationAvg = Math.round( _.sum(positives) / positives.length );
|
||||
else
|
||||
propagationAvg = 0;
|
||||
|
||||
this.stats.block = block;
|
||||
this.stats.propagationAvg = propagationAvg;
|
||||
|
||||
return this.getBlockStats();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Node.prototype.setPending = function(stats)
|
||||
{
|
||||
if( !_.isUndefined(stats) && !_.isUndefined(stats.pending) )
|
||||
@ -180,6 +205,16 @@ Node.prototype.getStats = function()
|
||||
};
|
||||
}
|
||||
|
||||
Node.prototype.getBlockStats = function()
|
||||
{
|
||||
return {
|
||||
id: this.id,
|
||||
block: this.stats.block,
|
||||
propagationAvg: this.stats.propagationAvg,
|
||||
history: this.history
|
||||
};
|
||||
}
|
||||
|
||||
Node.prototype.setState = function(active)
|
||||
{
|
||||
this.stats.active = active;
|
||||
|
@ -181,6 +181,32 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
|
||||
|
||||
break;
|
||||
|
||||
case "block":
|
||||
var index = findIndex({id: data.id});
|
||||
|
||||
if( index >= 0 && !_.isUndefined($scope.nodes[index]) && !_.isUndefined($scope.nodes[index].stats) )
|
||||
{
|
||||
if( $scope.nodes[index].stats.block.number < data.block.number )
|
||||
{
|
||||
var best = _.max($scope.nodes, function (node) {
|
||||
return parseInt(node.stats.block.number);
|
||||
}).stats.block;
|
||||
|
||||
if (data.block.number > best.number) {
|
||||
data.block.arrived = _.now();
|
||||
} else {
|
||||
data.block.arrived = best.arrived;
|
||||
}
|
||||
|
||||
$scope.nodes[index].history = data.history;
|
||||
}
|
||||
|
||||
$scope.nodes[index].stats.block = data.block;
|
||||
$scope.nodes[index].stats.propagationAvg = data.propagationAvg;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "pending":
|
||||
var index = findIndex({id: data.id});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user