updated to ethereum.js 0.1.2 and refactoring

This commit is contained in:
cubedro
2015-03-20 08:17:13 +02:00
parent 817ef1e032
commit e70f08914f
6 changed files with 39 additions and 81 deletions

View File

@@ -15,17 +15,17 @@ Socket = Primus.createSocket({
plugin: {emitter: Emitter, sparkLatency: Latency}
});
var INSTANCE_NAME,
ETH_VERSION;
var INSTANCE_NAME = process.env.INSTANCE_NAME;
var ETH_VERSION = "unknown";
if(process.env.NODE_ENV === 'production')
{
if(process.env.INSTANCE_NAME !== "")
if(process.env.INSTANCE_NAME === "")
{
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');
@@ -39,7 +39,7 @@ function Node()
this.info = {
name: INSTANCE_NAME || (process.env.EC2_INSTANCE_ID || os.hostname()),
node: ETH_VERSION || (process.env.ETH_VERSION || 'eth version 0.8.1'),
node: 'unknown',
os: os.platform(),
os_v: os.release()
};
@@ -76,7 +76,7 @@ function Node()
this.chainWatch = false;
this.updateInterval = false;
web3.setProvider(new web3.providers.HttpSyncProvider('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 || '8080')));
socket.on('open', function open() {
socket.emit('hello', { id: self.id, info: self.info, secret: WS_SECRET });
@@ -111,7 +111,7 @@ Node.prototype.isActive = function()
this.stats.errors = [];
try {
var peers = web3.eth.peerCount;
var peers = web3.net.peerCount;
if(peers !== null)
{
@@ -150,7 +150,7 @@ Node.prototype.getBlock = function(number)
if(typeof number === 'undefined'){
try {
number = parseInt(web3.eth.number);
number = parseInt(web3.eth.blockNumber);
if(number === this.stats.block.number + 1)
return this.stats.block;
@@ -165,7 +165,7 @@ Node.prototype.getBlock = function(number)
}
try {
block = web3.eth.block(number);
block = web3.eth.getBlock(number);
block.arrival = Date.now();
block.propagation = block.arrival - (block.timestamp * 1000);
@@ -174,7 +174,7 @@ Node.prototype.getBlock = function(number)
block.difficulty = web3.toDecimal(block.difficulty);
try {
block.txCount = web3.eth.transactionCount(block.hash) || '?';
block.txCount = web3.eth.getBlockTransactionCount(block.hash) || '?';
}
catch (err) {
this.stats.errors.push({
@@ -294,7 +294,7 @@ Node.prototype.getStats = function()
this.stats.mining = web3.eth.mining;
this.stats.gasPrice = web3.toDecimal(web3.eth.gasPrice);
this.stats.listening = web3.eth.listening;
this.stats.listening = web3.net.listening;
}
this.uptime();
@@ -306,7 +306,6 @@ Node.prototype.changed = function()
if(this._tries - this._lastSent > 5)
{
// console.log('force send');
this._lastSent = this._tries;
return true;
@@ -342,17 +341,18 @@ Node.prototype.setWatches = function()
{
var self = this;
this.pendingWatch = web3.eth.watch('pending');
this.pendingWatch.changed(function(log) {
this.pendingWatch = web3.eth.filter('pending');
this.pendingWatch.watch( function(log) {
console.log(log);
// console.log('pending changed');
self.stats.pending = parseInt(log.number);
// self.stats.pending = parseInt(log.number);
});
this.chainWatch = web3.eth.watch('chain');
this.chainWatch.messages(function(log) {
// console.log('block changed');
self.update();
});
// this.chainWatch = web3.eth.watch('chain');
// this.chainWatch.messages(function(log) {
// // console.log('block changed');
// self.update();
// });
this.updateInterval = setInterval(function(){
self.update();
@@ -386,10 +386,10 @@ Node.prototype.stop = function()
clearInterval(this.updateInterval);
if(this.pendingWatch)
this.pendingWatch.uninstall();
this.pendingWatch.stopWatching();
if(this.chainWatch)
this.chainWatch.uninstall();
// if(this.chainWatch)
// this.chainWatch.uninstall();
}
module.exports = Node;