From 6c0bf268b5c89991dab9cafb64f64e3d4ff55390 Mon Sep 17 00:00:00 2001 From: cubedro Date: Sun, 22 Mar 2015 22:26:55 +0200 Subject: [PATCH 1/3] fixed bug --- lib/node.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/node.js b/lib/node.js index 1cf4d37..797d30f 100644 --- a/lib/node.js +++ b/lib/node.js @@ -25,8 +25,8 @@ if(process.env.NODE_ENV === 'production') INSTANCE_NAME = shelljs.exec('ec2metadata --instance-id', {silent: true}).output; } - // ETH_VERSION = shelljs.exec((process.env.ETH_IMPLEMENTATION === 'go' ? 'ethereum version' : 'eth -V'), {silent: true}).output; } +ETH_VERSION = shelljs.exec((process.env.ETH_IMPLEMENTATION === 'go' ? 'ethereum version' : 'eth -V'), {silent: true}).output; var socket = new Socket(process.env.WS_SERVER || 'ws://localhost:3000'); var WS_SECRET = process.env.WS_SECRET || "eth-net-stats-has-a-secret"; @@ -37,9 +37,14 @@ function Node() { var self = this; - web3.setProvider(new web3.providers.HttpProvider('http://' + (process.env.RPC_HOST || 'localhost') + ':' + (process.env.RPC_PORT || '8080'))); + web3.setProvider(new web3.providers.HttpProvider('http://' + (process.env.RPC_HOST || 'localhost') + ':' + (process.env.RPC_PORT || '8545'))); - ETH_VERSION = web3.version; + try { + ETH_VERSION = web3.version; + } + catch (err) { + console.log("couldn't get Version"); + } this.info = { name: INSTANCE_NAME || (process.env.EC2_INSTANCE_ID || os.hostname()), @@ -295,7 +300,7 @@ Node.prototype.getStats = function() this.getLatestBlocks(); this.stats.mining = web3.eth.mining; - this.stats.gasPrice = web3.toDecimal(web3.eth.gasPrice); + this.stats.gasPrice = web3.eth.gasPrice.toString(10); this.stats.listening = web3.net.listening; } @@ -346,6 +351,7 @@ Node.prototype.setWatches = function() 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); }); @@ -384,6 +390,8 @@ Node.prototype.stop = function() if(this._socket) socket.end(); + web3.reset(); + if(this.updateInterval) clearInterval(this.updateInterval); From 491b2aa6f00307357c4b425d9a73ae1a219dd562 Mon Sep 17 00:00:00 2001 From: cubedro Date: Sun, 22 Mar 2015 22:55:15 +0200 Subject: [PATCH 2/3] fixed version for POC9 --- lib/node.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/node.js b/lib/node.js index 797d30f..5aba8a6 100644 --- a/lib/node.js +++ b/lib/node.js @@ -16,7 +16,6 @@ Socket = Primus.createSocket({ }); var INSTANCE_NAME = process.env.INSTANCE_NAME; -var ETH_VERSION = "unknown"; if(process.env.NODE_ENV === 'production') { @@ -26,7 +25,6 @@ if(process.env.NODE_ENV === 'production') } } -ETH_VERSION = shelljs.exec((process.env.ETH_IMPLEMENTATION === 'go' ? 'ethereum version' : 'eth -V'), {silent: true}).output; var socket = new Socket(process.env.WS_SERVER || 'ws://localhost:3000'); var WS_SECRET = process.env.WS_SECRET || "eth-net-stats-has-a-secret"; @@ -37,10 +35,12 @@ function Node() { var self = this; - 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'))); try { - ETH_VERSION = web3.version; + ETH_VERSION = web3.version.client; + NET_VERSION = web3.version.network; + API_VERSION = web3.version.api; } catch (err) { console.log("couldn't get Version"); @@ -48,7 +48,9 @@ function Node() this.info = { name: INSTANCE_NAME || (process.env.EC2_INSTANCE_ID || os.hostname()), - node: 'unknown', + node: ETH_VERSION, + net: NET_VERSION, + api: API_VERSION, os: os.platform(), os_v: os.release() }; From df58525fd42334803fad375b7eab9460d2bf96e9 Mon Sep 17 00:00:00 2001 From: cubedro Date: Sun, 22 Mar 2015 23:09:34 +0200 Subject: [PATCH 3/3] bug fixes --- lib/node.js | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/lib/node.js b/lib/node.js index 5aba8a6..5b928e4 100644 --- a/lib/node.js +++ b/lib/node.js @@ -8,6 +8,13 @@ var Primus = require('primus'), Latency = require('primus-spark-latency'), Socket; +var ETH_VERSION, + NET_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 || '8080'))); + Socket = Primus.createSocket({ transformer: 'websockets', pathname: '/api', @@ -15,15 +22,9 @@ Socket = Primus.createSocket({ plugin: {emitter: Emitter, sparkLatency: Latency} }); -var INSTANCE_NAME = process.env.INSTANCE_NAME; - -if(process.env.NODE_ENV === 'production') +if(process.env.NODE_ENV === 'production' && INSTANCE_NAME === "") { - if(process.env.INSTANCE_NAME === "") - { - INSTANCE_NAME = shelljs.exec('ec2metadata --instance-id', {silent: true}).output; - } - + INSTANCE_NAME = shelljs.exec('ec2metadata --instance-id', {silent: true}).output; } var socket = new Socket(process.env.WS_SERVER || 'ws://localhost:3000'); @@ -35,8 +36,6 @@ function Node() { var self = this; - web3.setProvider(new web3.providers.HttpProvider('http://' + (process.env.RPC_HOST || 'localhost') + ':' + (process.env.RPC_PORT || '8080'))); - try { ETH_VERSION = web3.version.client; NET_VERSION = web3.version.network; @@ -174,24 +173,13 @@ Node.prototype.getBlock = function(number) } try { - block = web3.eth.getBlock(number); + block = web3.eth.getBlock(number, true); block.arrival = Date.now(); block.propagation = block.arrival - (block.timestamp * 1000); if(block.hash != '?' && typeof block.difficulty !== 'undefined') { block.difficulty = web3.toDecimal(block.difficulty); - - try { - block.txCount = web3.eth.getBlockTransactionCount(block.hash) || '?'; - } - catch (err) { - this.stats.errors.push({ - code: '4', - msg: err - }); - console.log(err); - } } } catch (err) { @@ -279,7 +267,7 @@ Node.prototype.txDensityChart = function() { return txDensity = _.map(this.blocks, function(block) { - return block.txCount; + return block.transactions.length; }); } @@ -353,7 +341,7 @@ Node.prototype.setWatches = function() this.pendingWatch = web3.eth.filter('pending'); this.pendingWatch.watch( function(log) { console.log(log); - console.log(self.pendingWatch.get()); + // console.log(self.pendingWatch.get()); // console.log('pending changed'); // self.stats.pending = parseInt(log.number); });