Merge pull request #26 from cubedro/develop
Update to ethereum.js 0.2.1
This commit is contained in:
commit
6f682f4726
55
lib/node.js
55
lib/node.js
@ -13,7 +13,7 @@ var ETH_VERSION,
|
|||||||
API_VERSION;
|
API_VERSION;
|
||||||
var INSTANCE_NAME = process.env.INSTANCE_NAME;
|
var INSTANCE_NAME = process.env.INSTANCE_NAME;
|
||||||
|
|
||||||
web3.setProvider(new web3.providers.HttpProvider('http://' + (process.env.RPC_HOST || 'localhost') + ':' + (process.env.RPC_PORT || '8545')));
|
web3.setProvider(new web3.providers.HttpProvider('http://' + (process.env.RPC_HOST || 'localhost') + ':' + (process.env.RPC_PORT || '8080')));
|
||||||
|
|
||||||
Socket = Primus.createSocket({
|
Socket = Primus.createSocket({
|
||||||
transformer: 'websockets',
|
transformer: 'websockets',
|
||||||
@ -30,7 +30,7 @@ if(process.env.NODE_ENV === 'production' && INSTANCE_NAME === "")
|
|||||||
var socket = new Socket(process.env.WS_SERVER || 'ws://localhost:3000');
|
var socket = new Socket(process.env.WS_SERVER || 'ws://localhost:3000');
|
||||||
var WS_SECRET = process.env.WS_SECRET || "eth-net-stats-has-a-secret";
|
var WS_SECRET = process.env.WS_SECRET || "eth-net-stats-has-a-secret";
|
||||||
|
|
||||||
var MAX_BLOCKS_HISTORY = 12;
|
var MAX_BLOCKS_HISTORY = 36;
|
||||||
|
|
||||||
function Node()
|
function Node()
|
||||||
{
|
{
|
||||||
@ -42,7 +42,7 @@ function Node()
|
|||||||
API_VERSION = web3.version.api;
|
API_VERSION = web3.version.api;
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error("couldn't get Version");
|
console.error("Couldn't get version");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.info = {
|
this.info = {
|
||||||
@ -56,7 +56,7 @@ function Node()
|
|||||||
|
|
||||||
this.id = _.camelCase(this.info.name);
|
this.id = _.camelCase(this.info.name);
|
||||||
|
|
||||||
console.log(this.info);
|
console.info(this.info);
|
||||||
|
|
||||||
this.stats = {
|
this.stats = {
|
||||||
active: false,
|
active: false,
|
||||||
@ -70,6 +70,7 @@ function Node()
|
|||||||
difficulty: [],
|
difficulty: [],
|
||||||
txDensity: [],
|
txDensity: [],
|
||||||
blockTimes: [],
|
blockTimes: [],
|
||||||
|
gasSpending: [],
|
||||||
uptime: 0,
|
uptime: 0,
|
||||||
errors: []
|
errors: []
|
||||||
};
|
};
|
||||||
@ -82,8 +83,8 @@ function Node()
|
|||||||
this.blocks = [];
|
this.blocks = [];
|
||||||
|
|
||||||
this._socket = null;
|
this._socket = null;
|
||||||
this.pendingWatch = false;
|
this.pendingFilter = false;
|
||||||
this.chainWatch = false;
|
this.chainFilter = false;
|
||||||
this.updateInterval = false;
|
this.updateInterval = false;
|
||||||
|
|
||||||
socket.on('open', function open() {
|
socket.on('open', function open() {
|
||||||
@ -165,7 +166,7 @@ Node.prototype.getBlock = function(number)
|
|||||||
try {
|
try {
|
||||||
number = web3.eth.blockNumber;
|
number = web3.eth.blockNumber;
|
||||||
|
|
||||||
if(number === this.stats.block.number + 1)
|
if(number === this.stats.block.number)
|
||||||
return this.stats.block;
|
return this.stats.block;
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
@ -222,6 +223,7 @@ Node.prototype.getLatestBlocks = function()
|
|||||||
this.stats.blocktimeAvg = this.blockTimesAvg();
|
this.stats.blocktimeAvg = this.blockTimesAvg();
|
||||||
this.stats.difficulty = this.difficultyChart();
|
this.stats.difficulty = this.difficultyChart();
|
||||||
this.stats.txDensity = this.txDensityChart();
|
this.stats.txDensity = this.txDensityChart();
|
||||||
|
this.stats.gasSpending = this.gasSpendingChart();
|
||||||
}
|
}
|
||||||
|
|
||||||
Node.prototype.addBlockHistory = function(block)
|
Node.prototype.addBlockHistory = function(block)
|
||||||
@ -276,6 +278,14 @@ Node.prototype.txDensityChart = function()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Node.prototype.gasSpendingChart = function()
|
||||||
|
{
|
||||||
|
return gasSpending = _.map(this.blocks, function(block)
|
||||||
|
{
|
||||||
|
return block.gasUsed;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Node.prototype.uptime = function()
|
Node.prototype.uptime = function()
|
||||||
{
|
{
|
||||||
this.stats.uptime = ((this._tries - this._down) / this._tries) * 100;
|
this.stats.uptime = ((this._tries - this._down) / this._tries) * 100;
|
||||||
@ -294,6 +304,11 @@ Node.prototype.getStats = function()
|
|||||||
if(this.stats.block.number > 0)
|
if(this.stats.block.number > 0)
|
||||||
this.getLatestBlocks();
|
this.getLatestBlocks();
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.stats.pending = web3.eth.getBlockTransactionCount('pending');
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
this.stats.mining = web3.eth.mining;
|
this.stats.mining = web3.eth.mining;
|
||||||
this.stats.gasPrice = web3.eth.gasPrice.toString(10);
|
this.stats.gasPrice = web3.eth.gasPrice.toString(10);
|
||||||
this.stats.listening = web3.net.listening;
|
this.stats.listening = web3.net.listening;
|
||||||
@ -343,19 +358,15 @@ Node.prototype.setWatches = function()
|
|||||||
{
|
{
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// this.pendingWatch = web3.eth.filter('pending');
|
this.pendingFilter = web3.eth.filter('pending');
|
||||||
// this.pendingWatch.watch( function(log) {
|
this.pendingFilter.watch( function(log) {
|
||||||
// console.log(log);
|
self.update();
|
||||||
// // console.log(self.pendingWatch.get());
|
});
|
||||||
// // console.log('pending changed');
|
|
||||||
// // self.stats.pending = parseInt(log.number);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// this.chainWatch = web3.eth.watch('chain');
|
this.chainFilter = web3.eth.filter('latest');
|
||||||
// this.chainWatch.messages(function(log) {
|
this.chainFilter.watch(function(log) {
|
||||||
// // console.log('block changed');
|
self.update();
|
||||||
// self.update();
|
});
|
||||||
// });
|
|
||||||
|
|
||||||
this.updateInterval = setInterval(function(){
|
this.updateInterval = setInterval(function(){
|
||||||
self.update();
|
self.update();
|
||||||
@ -390,12 +401,6 @@ Node.prototype.stop = function()
|
|||||||
clearInterval(this.updateInterval);
|
clearInterval(this.updateInterval);
|
||||||
|
|
||||||
web3.reset();
|
web3.reset();
|
||||||
|
|
||||||
// if(this.pendingWatch)
|
|
||||||
// this.pendingWatch.stopWatching();
|
|
||||||
|
|
||||||
// if(this.chainWatch)
|
|
||||||
// this.chainWatch.uninstall();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Node;
|
module.exports = Node;
|
@ -8,10 +8,10 @@
|
|||||||
"lib": "./lib"
|
"lib": "./lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"debug": "~2.1.1",
|
"debug": "~2.1.3",
|
||||||
"ethereum.js": "0.1.*",
|
"ethereum.js": "0.2.1",
|
||||||
"lodash": "^3.2.0",
|
"lodash": "^3.6.0",
|
||||||
"primus": "^2.4.12",
|
"primus": "^3.0.2",
|
||||||
"primus-emit": "^0.1.2",
|
"primus-emit": "^0.1.2",
|
||||||
"primus-spark-latency": "^0.1.1",
|
"primus-spark-latency": "^0.1.1",
|
||||||
"shelljs": "^0.4.0",
|
"shelljs": "^0.4.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user