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;
|
||||
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({
|
||||
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 WS_SECRET = process.env.WS_SECRET || "eth-net-stats-has-a-secret";
|
||||
|
||||
var MAX_BLOCKS_HISTORY = 12;
|
||||
var MAX_BLOCKS_HISTORY = 36;
|
||||
|
||||
function Node()
|
||||
{
|
||||
@ -42,7 +42,7 @@ function Node()
|
||||
API_VERSION = web3.version.api;
|
||||
}
|
||||
catch (err) {
|
||||
console.error("couldn't get Version");
|
||||
console.error("Couldn't get version");
|
||||
}
|
||||
|
||||
this.info = {
|
||||
@ -56,7 +56,7 @@ function Node()
|
||||
|
||||
this.id = _.camelCase(this.info.name);
|
||||
|
||||
console.log(this.info);
|
||||
console.info(this.info);
|
||||
|
||||
this.stats = {
|
||||
active: false,
|
||||
@ -70,6 +70,7 @@ function Node()
|
||||
difficulty: [],
|
||||
txDensity: [],
|
||||
blockTimes: [],
|
||||
gasSpending: [],
|
||||
uptime: 0,
|
||||
errors: []
|
||||
};
|
||||
@ -82,8 +83,8 @@ function Node()
|
||||
this.blocks = [];
|
||||
|
||||
this._socket = null;
|
||||
this.pendingWatch = false;
|
||||
this.chainWatch = false;
|
||||
this.pendingFilter = false;
|
||||
this.chainFilter = false;
|
||||
this.updateInterval = false;
|
||||
|
||||
socket.on('open', function open() {
|
||||
@ -165,7 +166,7 @@ Node.prototype.getBlock = function(number)
|
||||
try {
|
||||
number = web3.eth.blockNumber;
|
||||
|
||||
if(number === this.stats.block.number + 1)
|
||||
if(number === this.stats.block.number)
|
||||
return this.stats.block;
|
||||
}
|
||||
catch (err) {
|
||||
@ -222,6 +223,7 @@ Node.prototype.getLatestBlocks = function()
|
||||
this.stats.blocktimeAvg = this.blockTimesAvg();
|
||||
this.stats.difficulty = this.difficultyChart();
|
||||
this.stats.txDensity = this.txDensityChart();
|
||||
this.stats.gasSpending = this.gasSpendingChart();
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
this.stats.uptime = ((this._tries - this._down) / this._tries) * 100;
|
||||
@ -294,6 +304,11 @@ Node.prototype.getStats = function()
|
||||
if(this.stats.block.number > 0)
|
||||
this.getLatestBlocks();
|
||||
|
||||
try {
|
||||
this.stats.pending = web3.eth.getBlockTransactionCount('pending');
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
this.stats.mining = web3.eth.mining;
|
||||
this.stats.gasPrice = web3.eth.gasPrice.toString(10);
|
||||
this.stats.listening = web3.net.listening;
|
||||
@ -343,19 +358,15 @@ Node.prototype.setWatches = function()
|
||||
{
|
||||
var self = this;
|
||||
|
||||
// this.pendingWatch = web3.eth.filter('pending');
|
||||
// this.pendingWatch.watch( function(log) {
|
||||
// console.log(log);
|
||||
// // console.log(self.pendingWatch.get());
|
||||
// // console.log('pending changed');
|
||||
// // self.stats.pending = parseInt(log.number);
|
||||
// });
|
||||
this.pendingFilter = web3.eth.filter('pending');
|
||||
this.pendingFilter.watch( function(log) {
|
||||
self.update();
|
||||
});
|
||||
|
||||
// this.chainWatch = web3.eth.watch('chain');
|
||||
// this.chainWatch.messages(function(log) {
|
||||
// // console.log('block changed');
|
||||
// self.update();
|
||||
// });
|
||||
this.chainFilter = web3.eth.filter('latest');
|
||||
this.chainFilter.watch(function(log) {
|
||||
self.update();
|
||||
});
|
||||
|
||||
this.updateInterval = setInterval(function(){
|
||||
self.update();
|
||||
@ -390,12 +401,6 @@ Node.prototype.stop = function()
|
||||
clearInterval(this.updateInterval);
|
||||
|
||||
web3.reset();
|
||||
|
||||
// if(this.pendingWatch)
|
||||
// this.pendingWatch.stopWatching();
|
||||
|
||||
// if(this.chainWatch)
|
||||
// this.chainWatch.uninstall();
|
||||
}
|
||||
|
||||
module.exports = Node;
|
@ -8,10 +8,10 @@
|
||||
"lib": "./lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": "~2.1.1",
|
||||
"ethereum.js": "0.1.*",
|
||||
"lodash": "^3.2.0",
|
||||
"primus": "^2.4.12",
|
||||
"debug": "~2.1.3",
|
||||
"ethereum.js": "0.2.1",
|
||||
"lodash": "^3.6.0",
|
||||
"primus": "^3.0.2",
|
||||
"primus-emit": "^0.1.2",
|
||||
"primus-spark-latency": "^0.1.1",
|
||||
"shelljs": "^0.4.0",
|
||||
|
Loading…
Reference in New Issue
Block a user