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

60 lines
1.2 KiB

var geoip = require('geoip-lite');
10 years ago
require('es6-promise').polyfill();
var Node = function Node(options, id)
{
this.info = options;
this.info.geo = geoip.lookup(this.info.rpcHost);
this.info.id = parseInt(id);
10 years ago
this.info.stats = {
active: false,
peers: 0,
mining: false,
block: {
height: 0,
hash: '?',
timestamp: 0
},
uptime: {
down: 0,
inc: 0,
total: 0
10 years ago
}
}
this.web3 = require('ethereum.js');
return this;
}
Node.prototype.update = function()
10 years ago
{
var sock = new this.web3.providers.HttpSyncProvider('http://' + this.info.rpcHost + ':' + this.info.rpcPort);
this.web3.setProvider(sock);
10 years ago
var eth = this.web3.eth;
try {
this.info.stats.peers = eth.peerCount;
}
catch (err) {
this.info.stats.peers = null;
}
if(this.info.stats.peers != null) {
this.info.stats.block = eth.block(parseInt(eth.number));
this.info.stats.mining = eth.mining;
this.info.stats.active = true;
} else {
this.info.stats.active = false;
this.info.stats.uptime.down++;
}
10 years ago
this.info.stats.uptime.inc++;
this.info.stats.uptime.total = ((this.info.stats.uptime.inc - this.info.stats.uptime.down) / this.info.stats.uptime.inc) * 100;
return this.info;
10 years ago
};
module.exports = Node;