Merge pull request #25 from cubedro/develop

Refactoring
This commit is contained in:
Marian OANCΞA 2015-03-27 13:40:07 +02:00
commit 763950c2d2
3 changed files with 28 additions and 23 deletions

6
app.js
View File

@ -3,13 +3,13 @@ var nodeModel = require('./lib/node');
var node = new nodeModel(); var node = new nodeModel();
var gracefulShutdown = function() { var gracefulShutdown = function() {
console.log("Received kill signal, shutting down gracefully."); console.warn("Received kill signal, shutting down gracefully.");
node.stop(); node.stop();
console.log("Closed node watcher"); console.info("Closed node watcher");
setTimeout(function(){ setTimeout(function(){
console.log("Closed out remaining connections."); console.info("Closed out remaining connections.");
process.exit(0) process.exit(0)
}, 2*1000); }, 2*1000);
} }

View File

@ -4,5 +4,5 @@ if [ -f /usr/bin/ethereum ]
then then
ethereum -rpc true ethereum -rpc true
else 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 fi

View File

@ -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 || '8080'))); web3.setProvider(new web3.providers.HttpProvider('http://' + (process.env.RPC_HOST || 'localhost') + ':' + (process.env.RPC_PORT || '8545')));
Socket = Primus.createSocket({ Socket = Primus.createSocket({
transformer: 'websockets', transformer: 'websockets',
@ -42,7 +42,7 @@ function Node()
API_VERSION = web3.version.api; API_VERSION = web3.version.api;
} }
catch (err) { catch (err) {
console.log("couldn't get Version"); console.error("couldn't get Version");
} }
this.info = { this.info = {
@ -88,16 +88,21 @@ function Node()
socket.on('open', function open() { socket.on('open', function open() {
socket.emit('hello', { id: self.id, info: self.info, secret: WS_SECRET }); socket.emit('hello', { id: self.id, info: self.info, secret: WS_SECRET });
console.log('The connection has been opened.'); console.info('The connection has been opened.');
console.log('Trying to login'); console.info('Trying to login');
}).on('end', function end() { })
.on('end', function end() {
self._socket = false; self._socket = false;
}).on('error', function error(err) { console.error('Socket connection closed');
console.log(err); })
}).on('reconnecting', function reconnecting(opts) { .on('error', function error(err) {
console.log('We are scheduling a reconnect operation', opts); console.error(err);
}).on('data', function incoming(data) { })
console.log('Received some data', data); .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() socket.on('ready', function()
@ -105,7 +110,7 @@ function Node()
self._socket = true; self._socket = true;
self.sendUpdate(true); self.sendUpdate(true);
console.log('The connection has been established.'); console.info('The connection has been established.');
}); });
this.init(); this.init();
@ -134,7 +139,7 @@ Node.prototype.isActive = function()
code: '1', code: '1',
msg: err msg: err
}); });
console.log(err); console.error(err);
} }
this.stats.active = false; this.stats.active = false;
@ -158,7 +163,7 @@ Node.prototype.getBlock = function(number)
if(typeof number === 'undefined'){ if(typeof number === 'undefined'){
try { try {
number = parseInt(web3.eth.blockNumber); number = web3.eth.blockNumber;
if(number === this.stats.block.number + 1) if(number === this.stats.block.number + 1)
return this.stats.block; return this.stats.block;
@ -168,7 +173,7 @@ Node.prototype.getBlock = function(number)
code: '3', code: '3',
msg: err msg: err
}); });
console.log(err); console.error(err);
} }
} }
@ -187,7 +192,7 @@ Node.prototype.getBlock = function(number)
code: '2', code: '2',
msg: err msg: err
}); });
console.log(err); console.error(err);
} }
return block; return block;
@ -340,7 +345,7 @@ Node.prototype.setWatches = function()
// this.pendingWatch = web3.eth.filter('pending'); // this.pendingWatch = web3.eth.filter('pending');
// this.pendingWatch.watch( function(log) { // this.pendingWatch.watch( function(log) {
// console.log(log); // console.log(log);
// // console.log(self.pendingWatch.get()); // // console.log(self.pendingWatch.get());
// // console.log('pending changed'); // // console.log('pending changed');
// // self.stats.pending = parseInt(log.number); // // self.stats.pending = parseInt(log.number);
@ -354,7 +359,7 @@ Node.prototype.setWatches = function()
this.updateInterval = setInterval(function(){ this.updateInterval = setInterval(function(){
self.update(); self.update();
}, 1000); }, 5000);
} }
Node.prototype.emit = function(message, payload) Node.prototype.emit = function(message, payload)
@ -364,7 +369,7 @@ Node.prototype.emit = function(message, payload)
socket.emit(message, payload); socket.emit(message, payload);
} }
catch (err) { catch (err) {
console.log(err); console.error(err);
} }
} }
} }