ethstats-server/src/pow/js/controllers.js

654 lines
16 KiB
JavaScript
Raw Normal View History

2015-01-20 19:29:31 +01:00
/* Controllers */
netStatsApp.controller('StatsCtrl', function($scope, $filter, $localStorage, socket, _, toastr) {
2015-01-20 19:29:31 +01:00
var MAX_BINS = 40;
2015-02-05 16:54:04 +01:00
// Main Stats init
// ---------------
2015-07-30 17:34:10 +02:00
$scope.frontierHash = '0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa';
2015-02-05 16:54:04 +01:00
$scope.nodesTotal = 0;
$scope.nodesActive = 0;
$scope.bestBlock = 0;
$scope.lastBlock = 0;
2015-02-18 08:54:04 +01:00
$scope.lastDifficulty = 0;
2015-02-05 16:54:04 +01:00
$scope.upTimeTotal = 0;
2015-02-18 08:54:04 +01:00
$scope.avgBlockTime = 0;
2015-04-28 17:44:41 +02:00
$scope.blockPropagationAvg = 0;
2015-04-28 11:54:32 +02:00
$scope.avgHashrate = 0;
2015-04-24 07:13:28 +02:00
$scope.uncleCount = 0;
2015-04-06 01:28:42 +02:00
$scope.bestStats = {};
2015-02-05 16:54:04 +01:00
2015-08-06 12:22:47 +02:00
$scope.lastGasLimit = _.fill(Array(MAX_BINS), 2);
$scope.lastBlocksTime = _.fill(Array(MAX_BINS), 2);
$scope.difficultyChart = _.fill(Array(MAX_BINS), 2);
$scope.transactionDensity = _.fill(Array(MAX_BINS), 2);
$scope.gasSpending = _.fill(Array(MAX_BINS), 2);
2015-04-06 01:28:42 +02:00
$scope.miners = [];
2015-03-27 17:52:42 +01:00
2015-02-17 11:14:48 +01:00
$scope.nodes = [];
2015-02-08 16:28:19 +01:00
$scope.map = [];
2015-04-23 15:17:31 +02:00
$scope.blockPropagationChart = [];
$scope.uncleCountChart = _.fill(Array(MAX_BINS), 2);
$scope.coinbases = [];
2015-02-08 16:03:05 +01:00
2015-04-06 07:33:01 +02:00
$scope.latency = 0;
2016-04-07 21:02:38 +02:00
$scope.currentApiVersion = "0.1.1";
2015-04-28 03:25:49 +02:00
$scope.predicate = $localStorage.predicate || ['-pinned', '-stats.active', '-stats.block.number', 'stats.block.propagation'];
$scope.reverse = $localStorage.reverse || false;
$scope.pinned = $localStorage.pinned || [];
2015-04-06 04:40:29 +02:00
2015-05-19 01:41:14 +02:00
$scope.prefixPredicate = ['-pinned', '-stats.active'];
$scope.originalPredicate = ['-stats.block.number', 'stats.block.propagation'];
$scope.orderTable = function(predicate, reverse)
{
2015-05-19 01:41:14 +02:00
if(!_.isEqual(predicate, $scope.originalPredicate))
{
$scope.reverse = reverse;
2015-05-19 01:41:14 +02:00
$scope.originalPredicate = predicate;
$scope.predicate = _.union($scope.prefixPredicate, predicate);
}
else
{
$scope.reverse = !$scope.reverse;
2015-05-19 01:41:14 +02:00
if($scope.reverse === true){
_.forEach(predicate, function (value, key) {
predicate[key] = (value[0] === '-' ? value.replace('-', '') : '-' + value);
});
}
$scope.predicate = _.union($scope.prefixPredicate, predicate);
}
$localStorage.predicate = $scope.predicate;
$localStorage.reverse = $scope.reverse;
}
$scope.pinNode = function(id)
{
index = findIndex({id: id});
if( !_.isUndefined($scope.nodes[index]) )
{
$scope.nodes[index].pinned = !$scope.nodes[index].pinned;
if($scope.nodes[index].pinned)
{
$scope.pinned.push(id);
}
else
{
$scope.pinned.splice($scope.pinned.indexOf(id), 1);
}
}
$localStorage.pinned = $scope.pinned;
}
2015-05-19 21:07:06 +02:00
var timeout = setInterval(function ()
{
$scope.$apply();
2015-06-13 11:54:34 +02:00
}, 300);
2015-02-23 15:48:00 +01:00
2015-05-19 10:07:48 +02:00
$scope.getNumber = function (num) {
return new Array(num);
}
2015-01-20 19:29:31 +01:00
// Socket listeners
// ----------------
2015-02-17 06:12:44 +01:00
socket.on('open', function open() {
socket.emit('ready');
console.log('The connection has been opened.');
2015-02-17 10:30:41 +01:00
})
.on('end', function end() {
2015-02-17 11:14:48 +01:00
console.log('Socket connection ended.')
2015-02-17 10:30:41 +01:00
})
.on('error', function error(err) {
2015-02-17 06:12:44 +01:00
console.log(err);
2015-02-17 10:30:41 +01:00
})
.on('reconnecting', function reconnecting(opts) {
2015-02-17 06:12:44 +01:00
console.log('We are scheduling a reconnect operation', opts);
2015-02-17 10:30:41 +01:00
})
.on('data', function incoming(data) {
2015-06-09 11:39:13 +02:00
$scope.$apply(socketAction(data.action, data.data));
2015-02-17 06:12:44 +01:00
});
2015-02-08 16:03:05 +01:00
socket.on('init', function(data)
{
2015-06-09 11:39:13 +02:00
$scope.$apply(socketAction("init", data.nodes));
2015-01-29 17:50:16 +01:00
});
2015-04-06 07:33:01 +02:00
socket.on('client-latency', function(data)
{
$scope.latency = data.latency;
})
2015-02-17 10:30:41 +01:00
function socketAction(action, data)
2015-02-08 16:03:05 +01:00
{
2015-08-11 19:40:28 +02:00
// filter data
data = xssFilter(data);
2015-04-29 11:03:05 +02:00
// console.log('Action: ', action);
// console.log('Data: ', data);
2015-02-17 11:14:48 +01:00
2015-06-03 02:51:19 +02:00
switch(action)
{
2015-02-17 11:14:48 +01:00
case "init":
$scope.nodes = data;
2015-04-17 11:10:20 +02:00
2015-05-19 10:07:48 +02:00
_.forEach($scope.nodes, function (node, index) {
2015-08-11 19:40:28 +02:00
2015-05-19 02:32:38 +02:00
// Init hashrate
2015-05-19 07:08:52 +02:00
if( _.isUndefined(node.stats.hashrate) )
2015-06-09 11:39:13 +02:00
node.stats.hashrate = 0;
// Init latency
latencyFilter(node);
2015-05-19 01:41:14 +02:00
2015-05-19 02:32:38 +02:00
// Init history
if( _.isUndefined(data.history) )
{
data.history = new Array(40);
_.fill(data.history, -1);
}
2015-05-19 07:08:52 +02:00
// Init or recover pin
2015-06-09 11:39:13 +02:00
node.pinned = ($scope.pinned.indexOf(node.id) >= 0 ? true : false);
2015-04-17 11:10:20 +02:00
});
2015-06-03 02:51:19 +02:00
if( $scope.nodes.length > 0 )
{
2015-04-17 11:10:20 +02:00
toastr['success']("Got nodes list", "Got nodes!");
2015-02-17 19:14:38 +01:00
2015-06-03 02:51:19 +02:00
updateActiveNodes();
}
2015-02-17 11:14:48 +01:00
break;
2015-02-17 10:30:41 +01:00
case "add":
2015-05-19 10:07:48 +02:00
var index = findIndex({id: data.id});
2015-04-17 11:10:20 +02:00
2015-08-28 06:34:34 +02:00
// if( addNewNode(data) )
// toastr['success']("New node "+ $scope.nodes[findIndex({id: data.id})].info.name +" connected!", "New node!");
// else
// toastr['info']("Node "+ $scope.nodes[index].info.name +" reconnected!", "Node is back!");
2015-02-17 10:30:41 +01:00
break;
2015-06-02 02:06:11 +02:00
// TODO: Remove when everybody updates api client to 0.0.12
2015-02-17 10:30:41 +01:00
case "update":
2015-04-06 16:08:36 +02:00
var index = findIndex({id: data.id});
2015-04-28 11:01:34 +02:00
2015-05-19 14:59:29 +02:00
if( index >= 0 && !_.isUndefined($scope.nodes[index]) && !_.isUndefined($scope.nodes[index].stats) )
{
2015-06-01 20:42:50 +02:00
if( !_.isUndefined($scope.nodes[index].stats.latency) )
data.stats.latency = $scope.nodes[index].stats.latency;
2015-05-19 14:59:29 +02:00
if( _.isUndefined(data.stats.hashrate) )
data.stats.hashrate = 0;
2015-05-18 17:33:20 +02:00
2015-05-19 10:07:48 +02:00
if( $scope.nodes[index].stats.block.number < data.stats.block.number )
2015-05-07 23:58:02 +02:00
{
2015-05-19 10:07:48 +02:00
var best = _.max($scope.nodes, function (node) {
2015-05-07 23:58:02 +02:00
return parseInt(node.stats.block.number);
}).stats.block;
if (data.stats.block.number > best.number) {
data.stats.block.arrived = _.now();
} else {
data.stats.block.arrived = best.arrived;
}
2015-05-19 10:07:48 +02:00
$scope.nodes[index].history = data.history;
2015-05-07 23:58:02 +02:00
}
2015-04-28 11:01:34 +02:00
$scope.nodes[index].stats = data.stats;
2015-06-03 02:51:19 +02:00
2015-06-13 11:54:34 +02:00
if( !_.isUndefined(data.stats.latency) && _.get($scope.nodes[index], 'stats.latency', 0) !== data.stats.latency )
{
$scope.nodes[index].stats.latency = data.stats.latency;
latencyFilter($scope.nodes[index]);
}
2015-06-03 02:51:19 +02:00
updateBestBlock();
2015-04-28 11:01:34 +02:00
}
2015-04-17 11:10:20 +02:00
2015-02-17 10:30:41 +01:00
break;
2015-06-01 22:02:32 +02:00
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;
2015-06-03 02:51:19 +02:00
updateBestBlock();
2015-06-01 22:02:32 +02:00
}
break;
2015-06-01 20:42:50 +02:00
case "pending":
var index = findIndex({id: data.id});
if( !_.isUndefined(data.id) && index >= 0 )
{
var node = $scope.nodes[index];
2015-06-01 23:04:34 +02:00
if( !_.isUndefined(node) && !_.isUndefined(node.stats.pending) && !_.isUndefined(data.pending) )
2015-06-01 20:42:50 +02:00
$scope.nodes[index].stats.pending = data.pending;
}
break;
2015-06-01 23:04:34 +02:00
case "stats":
var index = findIndex({id: data.id});
if( !_.isUndefined(data.id) && index >= 0 )
{
var node = $scope.nodes[index];
if( !_.isUndefined(node) && !_.isUndefined(node.stats) )
{
$scope.nodes[index].stats.active = data.stats.active;
$scope.nodes[index].stats.mining = data.stats.mining;
$scope.nodes[index].stats.hashrate = data.stats.hashrate;
$scope.nodes[index].stats.peers = data.stats.peers;
$scope.nodes[index].stats.gasPrice = data.stats.gasPrice;
$scope.nodes[index].stats.uptime = data.stats.uptime;
2015-06-03 02:51:19 +02:00
2015-06-13 11:54:34 +02:00
if( !_.isUndefined(data.stats.latency) && _.get($scope.nodes[index], 'stats.latency', 0) !== data.stats.latency )
{
$scope.nodes[index].stats.latency = data.stats.latency;
latencyFilter($scope.nodes[index]);
}
2015-06-03 02:51:19 +02:00
updateActiveNodes();
2015-06-01 23:04:34 +02:00
}
}
break;
2015-02-17 10:30:41 +01:00
case "info":
2015-05-19 10:07:48 +02:00
var index = findIndex({id: data.id});
2015-05-19 14:59:29 +02:00
if( index >= 0 )
{
$scope.nodes[index].info = data.info;
2015-04-17 11:10:20 +02:00
2015-05-19 14:59:29 +02:00
if( _.isUndefined($scope.nodes[index].pinned) )
$scope.nodes[index].pinned = false;
2015-06-03 02:51:19 +02:00
2015-06-09 11:39:13 +02:00
// Init latency
latencyFilter($scope.nodes[index]);
2015-06-03 02:51:19 +02:00
updateActiveNodes();
2015-05-19 14:59:29 +02:00
}
2015-04-17 11:10:20 +02:00
break;
case "blockPropagationChart":
2015-04-28 17:44:41 +02:00
$scope.blockPropagationChart = data.histogram;
$scope.blockPropagationAvg = data.avg;
2015-04-17 11:10:20 +02:00
2015-02-17 11:14:48 +01:00
break;
2015-02-18 07:06:41 +01:00
2015-04-24 05:23:26 +02:00
case "uncleCount":
2015-04-24 07:13:28 +02:00
$scope.uncleCount = data[0] + data[1];
data.reverse();
$scope.uncleCountChart = data;
2015-04-24 05:23:26 +02:00
break;
2015-04-28 09:43:56 +02:00
case "charts":
2015-05-20 16:17:59 +02:00
if( !_.isEqual($scope.avgBlockTime, data.avgBlocktime) )
$scope.avgBlockTime = data.avgBlocktime;
if( !_.isEqual($scope.avgHashrate, data.avgHashrate) )
$scope.avgHashrate = data.avgHashrate;
2015-08-06 12:22:47 +02:00
if( !_.isEqual($scope.lastGasLimit, data.gasLimit) && data.gasLimit.length >= MAX_BINS )
$scope.lastGasLimit = data.gasLimit;
if( !_.isEqual($scope.lastBlocksTime, data.blocktime) && data.blocktime.length >= MAX_BINS )
2015-05-20 16:17:59 +02:00
$scope.lastBlocksTime = data.blocktime;
if( !_.isEqual($scope.difficultyChart, data.difficulty) && data.difficulty.length >= MAX_BINS )
2015-05-20 16:17:59 +02:00
$scope.difficultyChart = data.difficulty;
if( !_.isEqual($scope.blockPropagationChart, data.propagation.histogram) ) {
$scope.blockPropagationChart = data.propagation.histogram;
$scope.blockPropagationAvg = data.propagation.avg;
}
data.uncleCount.reverse();
if( !_.isEqual($scope.uncleCountChart, data.uncleCount) && data.uncleCount.length >= MAX_BINS ) {
$scope.uncleCount = data.uncleCount[data.uncleCount.length-2] + data.uncleCount[data.uncleCount.length-1];
$scope.uncleCountChart = data.uncleCount;
2015-05-20 16:17:59 +02:00
}
if( !_.isEqual($scope.transactionDensity, data.transactions) && data.transactions.length >= MAX_BINS )
2015-05-20 16:17:59 +02:00
$scope.transactionDensity = data.transactions;
if( !_.isEqual($scope.gasSpending, data.gasSpending) && data.gasSpending.length >= MAX_BINS )
2015-05-20 16:17:59 +02:00
$scope.gasSpending = data.gasSpending;
if( !_.isEqual($scope.miners, data.miners) ) {
$scope.miners = data.miners;
getMinersNames();
}
2015-04-28 09:43:56 +02:00
break;
2015-02-18 07:06:41 +01:00
case "inactive":
2015-05-19 10:07:48 +02:00
var index = findIndex({id: data.id});
2015-05-19 14:59:29 +02:00
if( index >= 0 )
{
if( !_.isUndefined(data.stats) )
$scope.nodes[index].stats = data.stats;
2015-04-24 12:39:26 +02:00
2015-08-28 06:34:34 +02:00
// toastr['error']("Node "+ $scope.nodes[index].info.name +" went away!", "Node connection was lost!");
2015-06-03 02:51:19 +02:00
updateActiveNodes();
2015-05-19 14:59:29 +02:00
}
2015-04-17 11:10:20 +02:00
2015-02-18 07:06:41 +01:00
break;
2015-04-03 06:00:06 +02:00
case "latency":
2015-06-09 11:39:13 +02:00
if( !_.isUndefined(data.id) && !_.isUndefined(data.latency) )
2015-05-19 14:59:29 +02:00
{
2015-06-09 11:39:13 +02:00
var index = findIndex({id: data.id});
2015-04-17 11:10:20 +02:00
2015-06-09 11:39:13 +02:00
if( index >= 0 )
2015-06-03 02:51:19 +02:00
{
2015-06-09 11:39:13 +02:00
var node = $scope.nodes[index];
if( !_.isUndefined(node) && !_.isUndefined(node.stats) && !_.isUndefined(node.stats.latency) && node.stats.latency !== data.latency )
{
node.stats.latency = data.latency;
latencyFilter(node);
}
2015-06-03 02:51:19 +02:00
}
2015-05-19 14:59:29 +02:00
}
2015-05-19 02:32:38 +02:00
2015-04-03 06:00:06 +02:00
break;
2015-04-06 07:33:01 +02:00
case "client-ping":
2015-06-02 03:33:17 +02:00
socket.emit('client-pong', {
serverTime: data.serverTime,
clientTime: _.now()
});
2015-04-17 11:10:20 +02:00
2015-04-06 07:33:01 +02:00
break;
2015-02-17 10:30:41 +01:00
}
2015-01-29 17:50:16 +01:00
2015-06-09 11:39:13 +02:00
// $scope.$apply();
2015-02-17 10:30:41 +01:00
}
function findIndex(search)
{
return _.findIndex($scope.nodes, search);
}
2015-01-29 17:50:16 +01:00
2015-04-29 11:00:01 +02:00
function getMinersNames()
{
2015-05-19 10:07:48 +02:00
if( $scope.miners.length > 0 )
2015-04-29 11:03:05 +02:00
{
2015-05-19 10:07:48 +02:00
_.forIn($scope.miners, function (value, key)
2015-04-29 11:00:01 +02:00
{
if(value.name !== false)
return;
2015-05-18 17:33:20 +02:00
if(value.miner === "0x0000000000000000000000000000000000000000")
return;
2015-04-29 11:00:01 +02:00
var name = _.result(_.find(_.pluck($scope.nodes, 'info'), 'coinbase', value.miner), 'name');
2015-05-19 10:07:48 +02:00
if( !_.isUndefined(name) )
2015-04-29 11:00:01 +02:00
$scope.miners[key].name = name;
});
}
}
2015-02-17 19:14:38 +01:00
function addNewNode(data)
{
var index = findIndex({id: data.id});
2015-04-24 12:39:26 +02:00
2015-05-19 10:07:48 +02:00
if( _.isUndefined(data.history) )
{
data.history = new Array(40);
_.fill(data.history, -1);
}
2015-05-19 01:41:14 +02:00
2015-05-19 10:07:48 +02:00
if( index < 0 )
{
if( !_.isUndefined(data.stats) && _.isUndefined(data.stats.hashrate) )
2015-05-19 02:32:38 +02:00
{
2015-05-19 10:07:48 +02:00
data.stats.hashrate = 0;
2015-05-19 02:32:38 +02:00
}
2015-05-19 10:07:48 +02:00
data.pinned = false;
2015-02-17 19:14:38 +01:00
$scope.nodes.push(data);
return true;
}
2015-05-19 10:07:48 +02:00
data.pinned = ( !_.isUndefined($scope.nodes[index].pinned) ? $scope.nodes[index].pinned : false);
2015-05-19 10:07:48 +02:00
if( !_.isUndefined($scope.nodes[index].history) )
2015-05-19 02:32:38 +02:00
{
2015-05-19 10:07:48 +02:00
data.history = $scope.nodes[index].history;
2015-05-19 02:32:38 +02:00
}
2015-02-17 19:14:38 +01:00
$scope.nodes[index] = data;
2015-06-03 02:51:19 +02:00
updateActiveNodes();
2015-02-17 19:14:38 +01:00
return false;
}
2015-06-03 02:51:19 +02:00
function updateActiveNodes()
{
updateBestBlock();
$scope.nodesTotal = $scope.nodes.length;
$scope.nodesActive = _.filter($scope.nodes, function (node) {
2015-07-30 19:34:34 +02:00
// forkFilter(node);
2015-06-03 02:51:19 +02:00
return node.stats.active == true;
}).length;
$scope.upTimeTotal = _.reduce($scope.nodes, function (total, node) {
return total + node.stats.uptime;
}, 0) / $scope.nodes.length;
$scope.map = _.map($scope.nodes, function (node) {
var fill = $filter('bubbleClass')(node.stats, $scope.bestBlock);
if(node.geo != null)
return {
radius: 3,
latitude: node.geo.ll[0],
longitude: node.geo.ll[1],
nodeName: node.info.name,
fillClass: "text-" + fill,
fillKey: fill,
};
else
return {
radius: 0,
latitude: 0,
longitude: 0
};
});
}
function updateBestBlock()
2015-01-29 17:50:16 +01:00
{
2015-05-19 10:07:48 +02:00
if( $scope.nodes.length )
2015-02-17 10:30:41 +01:00
{
2015-06-09 18:28:29 +02:00
var chains = {};
var maxScore = 0;
2015-07-30 19:34:34 +02:00
// _($scope.nodes)
// .map(function (item)
// {
// maxScore += (item.trusted ? 50 : 1);
// if( _.isUndefined(chains[item.stats.block.number]) )
// chains[item.stats.block.number] = [];
// if( _.isUndefined(chains[item.stats.block.number][item.stats.block.fork]) )
// chains[item.stats.block.number][item.stats.block.fork] = {
// fork: item.stats.block.fork,
// count: 0,
// trusted: 0,
// score: 0
// };
// if(item.stats.block.trusted)
// chains[item.stats.block.number][item.stats.block.fork].trusted++;
// else
// chains[item.stats.block.number][item.stats.block.fork].count++;
// chains[item.stats.block.number][item.stats.block.fork].score = chains[item.stats.block.number][item.stats.block.fork].trusted * 50 + chains[item.stats.block.number][item.stats.block.fork].count;
// })
// .value();
// $scope.maxScore = maxScore;
// $scope.chains = _.reduce(chains, function (result, item, key)
// {
// result[key] = _.max(item, 'score');
// return result;
// }, {});
2015-06-09 18:28:29 +02:00
var bestBlock = _.max($scope.nodes, function (node)
{
2015-06-17 03:20:43 +02:00
// if( $scope.chains[node.stats.block.number].fork === node.stats.block.fork && $scope.chains[node.stats.block.number].score / $scope.maxScore >= 0.5 )
// {
2015-06-09 18:28:29 +02:00
return parseInt(node.stats.block.number);
2015-06-17 03:20:43 +02:00
// }
2015-06-09 18:28:29 +02:00
2015-06-17 03:20:43 +02:00
// return 0;
2015-04-24 10:44:21 +02:00
}).stats.block.number;
2015-02-17 10:30:41 +01:00
if( bestBlock !== $scope.bestBlock )
2015-04-04 21:35:45 +02:00
{
2015-04-24 10:44:21 +02:00
$scope.bestBlock = bestBlock;
2015-05-19 10:07:48 +02:00
$scope.bestStats = _.max($scope.nodes, function (node) {
2015-04-04 21:35:45 +02:00
return parseInt(node.stats.block.number);
2015-04-06 01:28:42 +02:00
}).stats;
2015-02-17 10:30:41 +01:00
2015-05-07 23:58:02 +02:00
$scope.lastBlock = $scope.bestStats.block.arrived;
2015-04-24 18:49:39 +02:00
$scope.lastDifficulty = $scope.bestStats.block.difficulty;
2015-04-04 21:35:45 +02:00
}
2015-02-17 10:30:41 +01:00
}
2015-01-29 17:50:16 +01:00
}
2015-06-09 11:39:13 +02:00
2015-07-30 19:34:34 +02:00
// function forkFilter(node)
// {
// if( _.isUndefined(node.readable) )
// node.readable = {};
2015-06-09 18:28:29 +02:00
2015-07-30 19:34:34 +02:00
// node.readable.forkClass = 'hidden';
// node.readable.forkMessage = '';
2015-06-13 11:54:34 +02:00
2015-07-30 19:34:34 +02:00
// return true;
2015-06-13 11:54:34 +02:00
2015-07-30 19:34:34 +02:00
// if( $scope.chains[node.stats.block.number].fork === node.stats.block.fork && $scope.chains[node.stats.block.number].score / $scope.maxScore >= 0.5 )
// {
// node.readable.forkClass = 'hidden';
// node.readable.forkMessage = '';
2015-06-09 18:28:29 +02:00
2015-07-30 19:34:34 +02:00
// return true;
// }
2015-06-09 18:28:29 +02:00
2015-07-30 19:34:34 +02:00
// if( $scope.chains[node.stats.block.number].fork !== node.stats.block.fork )
// {
// node.readable.forkClass = 'text-danger';
// node.readable.forkMessage = 'Wrong chain.<br/>This chain is a fork.';
2015-06-09 18:28:29 +02:00
2015-07-30 19:34:34 +02:00
// return false;
// }
2015-06-09 18:28:29 +02:00
2015-07-30 19:34:34 +02:00
// if( $scope.chains[node.stats.block.number].score / $scope.maxScore < 0.5)
// {
// node.readable.forkClass = 'text-warning';
// node.readable.forkMessage = 'May not be main chain.<br/>Waiting for more confirmations.';
2015-06-09 18:28:29 +02:00
2015-07-30 19:34:34 +02:00
// return false;
// }
// }
2015-06-09 18:28:29 +02:00
2015-06-09 11:39:13 +02:00
function latencyFilter(node)
{
if( _.isUndefined(node.readable) )
node.readable = {};
if( _.isUndefined(node.stats) ) {
node.readable.latencyClass = 'text-danger';
node.readable.latency = 'offline';
}
if (node.stats.active === false)
{
node.readable.latencyClass = 'text-danger';
node.readable.latency = 'offline';
}
else
{
if (node.stats.latency <= 100)
node.readable.latencyClass = 'text-success';
if (node.stats.latency > 100 && node.stats.latency <= 1000)
node.readable.latencyClass = 'text-warning';
if (node.stats.latency > 1000)
node.readable.latencyClass = 'text-danger';
node.readable.latency = node.stats.latency + ' ms';
}
}
2015-08-11 19:40:28 +02:00
// very simple xss filter
function xssFilter(obj){
if(_.isArray(obj)) {
return _.map(obj, xssFilter);
} else if(_.isObject(obj)) {
return _.mapValues(obj, xssFilter);
} else if(_.isString(obj)) {
return obj.replace(/\< *\/* *script *>*/gi,'').replace(/javascript/gi,'');
} else
return obj;
}
2015-04-29 12:58:09 +02:00
});