From 0e76e169ca3be50c60171b0cc31979daf07b8d9d Mon Sep 17 00:00:00 2001 From: cubedro Date: Fri, 27 Mar 2015 13:56:11 +0200 Subject: [PATCH 1/8] refactoring --- lib/node.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node.js b/lib/node.js index bb5eaef..026acbe 100644 --- a/lib/node.js +++ b/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', @@ -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, From a25d1aa90f299fda5c876f4579e21c1b73c062e3 Mon Sep 17 00:00:00 2001 From: cubedro Date: Fri, 27 Mar 2015 20:26:45 +0200 Subject: [PATCH 2/8] updated ethereum.js to 0.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 22f4a28..1bbaa2b 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ }, "dependencies": { "debug": "~2.1.1", - "ethereum.js": "0.1.*", + "ethereum.js": "0.2.0", "lodash": "^3.2.0", "primus": "^2.4.12", "primus-emit": "^0.1.2", From 3652e58b7f62fbd4a90ccc850ff19f0666f832d5 Mon Sep 17 00:00:00 2001 From: cubedro Date: Fri, 27 Mar 2015 21:11:21 +0200 Subject: [PATCH 3/8] v0.2.0 updates --- lib/node.js | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/lib/node.js b/lib/node.js index 026acbe..99d83f4 100644 --- a/lib/node.js +++ b/lib/node.js @@ -82,8 +82,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() { @@ -343,19 +343,18 @@ 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) { + console.log('pending changed', log); + // console.log(self.pendingFilter.get()); + // self.stats.pending = parseInt(log.number); + }); - // 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) { + console.log('block changed:', log); + // self.update(); + }); this.updateInterval = setInterval(function(){ self.update(); @@ -390,12 +389,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; \ No newline at end of file From 13f96e05e5b7f685e5193605bbef074b87a99742 Mon Sep 17 00:00:00 2001 From: cubedro Date: Sat, 28 Mar 2015 01:28:55 +0200 Subject: [PATCH 4/8] fixed recentBlock & increased block history --- lib/node.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/node.js b/lib/node.js index 99d83f4..ebe5325 100644 --- a/lib/node.js +++ b/lib/node.js @@ -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() { @@ -165,7 +165,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) { @@ -343,18 +343,18 @@ Node.prototype.setWatches = function() { var self = this; - this.pendingFilter = web3.eth.filter('pending'); - this.pendingFilter.watch( function(log) { - console.log('pending changed', log); - // console.log(self.pendingFilter.get()); - // self.stats.pending = parseInt(log.number); - }); + // this.pendingFilter = web3.eth.filter('pending'); + // this.pendingFilter.watch( function(log) { + // console.log('pending changed', log); + // // console.log(self.pendingFilter.get()); + // // self.stats.pending = parseInt(log.number); + // }); - this.chainFilter = web3.eth.filter('latest'); - this.chainFilter.watch(function(log) { - console.log('block changed:', log); - // self.update(); - }); + // this.chainFilter = web3.eth.filter('latest'); + // this.chainFilter.watch(function(log) { + // console.log('block changed:', log); + // // self.update(); + // }); this.updateInterval = setInterval(function(){ self.update(); From e2ea53de8a927c361817e646f2066635b7b176be Mon Sep 17 00:00:00 2001 From: cubedro Date: Sat, 28 Mar 2015 15:34:34 +0200 Subject: [PATCH 5/8] updated packages --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 1bbaa2b..cc35c07 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,10 @@ "lib": "./lib" }, "dependencies": { - "debug": "~2.1.1", + "debug": "~2.1.3", "ethereum.js": "0.2.0", - "lodash": "^3.2.0", - "primus": "^2.4.12", + "lodash": "^3.6.0", + "primus": "^3.0.2", "primus-emit": "^0.1.2", "primus-spark-latency": "^0.1.1", "shelljs": "^0.4.0", From 0a0e95df135c92bb4a327f9d964c41b81ed10aed Mon Sep 17 00:00:00 2001 From: cubedro Date: Sat, 28 Mar 2015 19:16:52 +0200 Subject: [PATCH 6/8] updated ethereum.js --- lib/node.js | 22 +++++++++++----------- package.json | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/node.js b/lib/node.js index ebe5325..a1a9292 100644 --- a/lib/node.js +++ b/lib/node.js @@ -343,18 +343,18 @@ Node.prototype.setWatches = function() { var self = this; - // this.pendingFilter = web3.eth.filter('pending'); - // this.pendingFilter.watch( function(log) { - // console.log('pending changed', log); - // // console.log(self.pendingFilter.get()); - // // self.stats.pending = parseInt(log.number); - // }); + this.pendingFilter = web3.eth.filter('pending'); + this.pendingFilter.watch( function(log) { + console.log('pending changed:', log); + // console.log(self.pendingFilter.get()); + // self.stats.pending = parseInt(log.number); + }); - // this.chainFilter = web3.eth.filter('latest'); - // this.chainFilter.watch(function(log) { - // console.log('block changed:', log); - // // self.update(); - // }); + this.chainFilter = web3.eth.filter('latest'); + this.chainFilter.watch(function(log) { + console.log('block changed:', log); + self.update(); + }); this.updateInterval = setInterval(function(){ self.update(); diff --git a/package.json b/package.json index cc35c07..85021fd 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ }, "dependencies": { "debug": "~2.1.3", - "ethereum.js": "0.2.0", + "ethereum.js": "0.2.1", "lodash": "^3.6.0", "primus": "^3.0.2", "primus-emit": "^0.1.2", From 40951f63012debafd4c3ee4fda56998b0995cecd Mon Sep 17 00:00:00 2001 From: cubedro Date: Sat, 28 Mar 2015 19:46:06 +0200 Subject: [PATCH 7/8] added pending txs --- lib/node.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/node.js b/lib/node.js index a1a9292..5ad9dc1 100644 --- a/lib/node.js +++ b/lib/node.js @@ -294,6 +294,7 @@ Node.prototype.getStats = function() if(this.stats.block.number > 0) this.getLatestBlocks(); + self.stats.pending = web3.eth.getBlockTransactionCount('pending'); this.stats.mining = web3.eth.mining; this.stats.gasPrice = web3.eth.gasPrice.toString(10); this.stats.listening = web3.net.listening; @@ -345,14 +346,11 @@ Node.prototype.setWatches = function() this.pendingFilter = web3.eth.filter('pending'); this.pendingFilter.watch( function(log) { - console.log('pending changed:', log); - // console.log(self.pendingFilter.get()); - // self.stats.pending = parseInt(log.number); + self.update(); }); this.chainFilter = web3.eth.filter('latest'); this.chainFilter.watch(function(log) { - console.log('block changed:', log); self.update(); }); From fc70b2870655552f90f8a983d9b42bb698cb190d Mon Sep 17 00:00:00 2001 From: cubedro Date: Sat, 28 Mar 2015 20:06:46 +0200 Subject: [PATCH 8/8] added gas spending --- lib/node.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/node.js b/lib/node.js index 5ad9dc1..849c397 100644 --- a/lib/node.js +++ b/lib/node.js @@ -70,6 +70,7 @@ function Node() difficulty: [], txDensity: [], blockTimes: [], + gasSpending: [], uptime: 0, errors: [] }; @@ -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,7 +304,11 @@ Node.prototype.getStats = function() if(this.stats.block.number > 0) this.getLatestBlocks(); - self.stats.pending = web3.eth.getBlockTransactionCount('pending'); + 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;