From 9f62909dca410628a91311830d0590df7fa89f92 Mon Sep 17 00:00:00 2001 From: cubedro Date: Fri, 27 Mar 2015 11:21:17 +0200 Subject: [PATCH 1/2] added verbosity flag --- bin/eth.sh | 2 +- lib/node.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/eth.sh b/bin/eth.sh index 3a3964d..a81cc3a 100644 --- a/bin/eth.sh +++ b/bin/eth.sh @@ -4,5 +4,5 @@ if [ -f /usr/bin/ethereum ] then ethereum -rpc true else - eth -x 15 -l 30303 -r poc-8.ethdev.com -p 30303 -m off -j + eth -x 15 -l 30303 -r poc-8.ethdev.com -p 30303 -m off -v 1 -j fi \ No newline at end of file diff --git a/lib/node.js b/lib/node.js index 63aaab8..c074f76 100644 --- a/lib/node.js +++ b/lib/node.js @@ -340,7 +340,7 @@ Node.prototype.setWatches = function() // this.pendingWatch = web3.eth.filter('pending'); // this.pendingWatch.watch( function(log) { - // console.log(log); + // console.log(log); // // console.log(self.pendingWatch.get()); // // console.log('pending changed'); // // self.stats.pending = parseInt(log.number); From 399712168c0dcc8c7a15e44d20950d205b509d67 Mon Sep 17 00:00:00 2001 From: cubedro Date: Fri, 27 Mar 2015 13:38:41 +0200 Subject: [PATCH 2/2] refactoring --- app.js | 6 +++--- lib/node.js | 41 +++++++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app.js b/app.js index 8ba9257..3bd8026 100644 --- a/app.js +++ b/app.js @@ -3,13 +3,13 @@ var nodeModel = require('./lib/node'); var node = new nodeModel(); var gracefulShutdown = function() { - console.log("Received kill signal, shutting down gracefully."); + console.warn("Received kill signal, shutting down gracefully."); node.stop(); - console.log("Closed node watcher"); + console.info("Closed node watcher"); setTimeout(function(){ - console.log("Closed out remaining connections."); + console.info("Closed out remaining connections."); process.exit(0) }, 2*1000); } diff --git a/lib/node.js b/lib/node.js index c074f76..bb5eaef 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 || '8080'))); +web3.setProvider(new web3.providers.HttpProvider('http://' + (process.env.RPC_HOST || 'localhost') + ':' + (process.env.RPC_PORT || '8545'))); Socket = Primus.createSocket({ transformer: 'websockets', @@ -42,7 +42,7 @@ function Node() API_VERSION = web3.version.api; } catch (err) { - console.log("couldn't get Version"); + console.error("couldn't get Version"); } this.info = { @@ -88,16 +88,21 @@ function Node() socket.on('open', function open() { socket.emit('hello', { id: self.id, info: self.info, secret: WS_SECRET }); - console.log('The connection has been opened.'); - console.log('Trying to login'); - }).on('end', function end() { + console.info('The connection has been opened.'); + console.info('Trying to login'); + }) + .on('end', function end() { self._socket = false; - }).on('error', function error(err) { - console.log(err); - }).on('reconnecting', function reconnecting(opts) { - console.log('We are scheduling a reconnect operation', opts); - }).on('data', function incoming(data) { - console.log('Received some data', data); + console.error('Socket connection closed'); + }) + .on('error', function error(err) { + console.error(err); + }) + .on('reconnecting', function reconnecting(opts) { + console.warn('We are scheduling a reconnect operation', opts); + }) + .on('data', function incoming(data) { + console.info('Received some data', data); }); socket.on('ready', function() @@ -105,7 +110,7 @@ function Node() self._socket = true; self.sendUpdate(true); - console.log('The connection has been established.'); + console.info('The connection has been established.'); }); this.init(); @@ -134,7 +139,7 @@ Node.prototype.isActive = function() code: '1', msg: err }); - console.log(err); + console.error(err); } this.stats.active = false; @@ -158,7 +163,7 @@ Node.prototype.getBlock = function(number) if(typeof number === 'undefined'){ try { - number = parseInt(web3.eth.blockNumber); + number = web3.eth.blockNumber; if(number === this.stats.block.number + 1) return this.stats.block; @@ -168,7 +173,7 @@ Node.prototype.getBlock = function(number) code: '3', msg: err }); - console.log(err); + console.error(err); } } @@ -187,7 +192,7 @@ Node.prototype.getBlock = function(number) code: '2', msg: err }); - console.log(err); + console.error(err); } return block; @@ -354,7 +359,7 @@ Node.prototype.setWatches = function() this.updateInterval = setInterval(function(){ self.update(); - }, 1000); + }, 5000); } Node.prototype.emit = function(message, payload) @@ -364,7 +369,7 @@ Node.prototype.emit = function(message, payload) socket.emit(message, payload); } catch (err) { - console.log(err); + console.error(err); } } }