Ethereum network status dashboard for PoW and PoA networks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ethstats-server/models/node.js

75 lines
1.2 KiB

var geoip = require('geoip-lite');
var Node = function Node(data)
10 years ago
{
10 years ago
this.id = null;
this.info = {};
this.geo = {}
this.stats = {
10 years ago
active: false,
10 years ago
listening: false,
10 years ago
mining: false,
10 years ago
peers: 0,
pending: 0,
gasPrice: 0,
block: {
difficulty: 0,
number: 0,
gasLimit: 0,
timestamp: 0,
blocktime: 0
},
10 years ago
blocktimeAvg: 0,
difficulty: [],
uptime: 0,
10 years ago
lastUpdate: 0
};
10 years ago
if(typeof data.id !== 'undefined')
this.id = data.id;
if(typeof data.info !== 'undefined')
this.info = data.info;
if(typeof data.ip !== 'undefined'){
this.info.ip = data.ip;
this.setGeo(data.ip);
}
if(typeof data.spark !== 'undefined')
this.spark = data.spark;
10 years ago
return this;
}
Node.prototype.setGeo = function(ip)
10 years ago
{
10 years ago
this.geo = geoip.lookup(ip);
}
Node.prototype.setInfo = function(data)
{
if(typeof data.info !== 'undefined')
this.info = data.info;
if(typeof data.ip !== 'undefined'){
this.info.ip = data.ip;
this.setGeo(data.ip);
}
if(typeof data.spark !== 'undefined')
this.spark = data.spark;
}
Node.prototype.getInfo = function()
{
return {id: this.id, info: this.info, geo: this.geo, stats: this.stats};
}
Node.prototype.getStats = function()
{
return {id: this.id, stats: this.stats};
}
module.exports = Node;