From 7dafb71c8f923fba9df797a6fdd52e61242e248d Mon Sep 17 00:00:00 2001 From: cubedro Date: Fri, 24 Apr 2015 12:38:26 +0300 Subject: [PATCH] added coinbase + refactoring --- lib/node.js | 78 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/lib/node.js b/lib/node.js index 9ae75db..89cc2b2 100644 --- a/lib/node.js +++ b/lib/node.js @@ -17,6 +17,7 @@ var ETH_VERSION, API_VERSION; var INSTANCE_NAME = process.env.INSTANCE_NAME; +var COINBASE = ''; var Contract = null; @@ -53,6 +54,7 @@ function Node() NET_VERSION = web3.version.network; PROTOCOL_VERSION = web3.toDecimal(web3.version.ethereum); API_VERSION = web3.version.api; + COINBASE = web3.eth.coinbase; } catch (err) { console.error("Couldn't get version"); @@ -68,7 +70,8 @@ function Node() port: (process.env.LISTENING_PORT || 30303), os: os.platform(), os_v: os.release(), - client: pjson.version + client: pjson.version, + coinbase: COINBASE }; this.id = _.camelCase(this.info.name); @@ -326,18 +329,18 @@ Node.prototype.getMinerName = function(miner) } else { - var name = this._Registrar.name(miner); + if(this._Registrar !== null) + { + var name = this._Registrar.name(miner); - if(name.length > 0) - { - this._knownMiners.push({miner: miner, name: name}); - return name; - } - else - { - this._knownMiners.push({miner: miner, name: false}); - return false; + if(name.length > 0) + { + this._knownMiners.push({miner: miner, name: name}); + return name; + } } + + this._knownMiners.push({miner: miner, name: false}); } return false; @@ -480,21 +483,35 @@ Node.prototype.setWatches = function() { var self = this; - this.pendingFilter = web3.eth.filter('pending'); - this.pendingFilter.watch( function(log) { - if(PENDING_WORKS) { - debounce(function() { - self.updatePending(); - }, 50); - } - }); + try { + this.pendingFilter = web3.eth.filter('pending'); + this.pendingFilter.watch( function(log) { + if(PENDING_WORKS) { + debounce(function() { + self.updatePending(); + }, 50); + } + }); + } + catch (err) + { + console.error("Couldn't set up pending filter"); + console.error(err); + } - this.chainFilter = web3.eth.filter('latest'); - this.chainFilter.watch(function(log) { - debounce(function() { - self.update(); - }, 50); - }); + try { + this.chainFilter = web3.eth.filter('latest'); + this.chainFilter.watch(function(log) { + debounce(function() { + self.update(); + }, 50); + }); + } + catch (err) + { + console.error("Couldn't set up chain filter"); + console.error(err); + } this.updateInterval = setInterval(function(){ self.update(); @@ -519,8 +536,15 @@ Node.prototype.emit = function(message, payload) Node.prototype.installContract = function() { - Contract = web3.eth.contract(registrar.desc); - this._Registrar = new Contract(registrar.address); + try { + Contract = web3.eth.contract(registrar.desc); + this._Registrar = new Contract(registrar.address); + } + catch (err) + { + console.error("Couldn't set up registrar contract"); + console.error(err); + } } Node.prototype.init = function()