Merge pull request #20 from cubedro/develop

Updated to ethereum.js 0.1.2 and refactoring
This commit is contained in:
Marian OANCΞA 2015-03-20 08:17:47 +02:00
commit 516bc20faa
6 changed files with 39 additions and 81 deletions

View File

@ -1,27 +1,19 @@
#!/bin/sh #!/bin/sh
mkdir -p ~/go # update repository & install dependencies
echo "export GOPATH=$HOME/go" >> ~/.bashrc sudo apt-get install -y software-properties-common
echo "export PATH=$PATH:$HOME/go/bin:/usr/local/go/bin" >> ~/.bashrc
export GOPATH=$HOME/go
export PATH=$PATH:$HOME/go/bin:/usr/local/go/bin
sudo apt-get update -y sudo apt-get update -y
sudo apt-get upgrade -y sudo apt-get upgrade -y
sudo apt-get install -y git mercurial build-essential software-properties-common wget pkg-config libgmp3-dev libreadline6-dev libpcre3-dev libpcre++-dev nodejs npm sudo apt-get install -y git mercurial build-essential software-properties-common wget pkg-config libgmp3-dev libreadline6-dev libpcre3-dev libpcre++-dev nodejs npm
# install go # add ethereum repos
sudo apt-get install -y golang sudo add-apt-repository -y ppa:ethereum/ethereum-qt
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo add-apt-repository -y ppa:ethereum/ethereum-dev
sudo apt-get update -y
go get -v github.com/tools/godep #install ethereum
go get -v -d github.com/ethereum/go-ethereum/... sudo apt-get install -y ethereum
# install ethereum go
cd $GOPATH/src/github.com/ethereum/go-ethereum
git checkout develop
godep restore
go install -v ./cmd/ethereum
# add node symlink # add node symlink
sudo ln -s /usr/bin/nodejs /usr/bin/node sudo ln -s /usr/bin/nodejs /usr/bin/node

View File

@ -1,3 +1,8 @@
#!/bin/bash #!/bin/bash
trap "exit" INT trap "exit" INT
/home/ubuntu/bin/eth -b -x 15 -l 30303 -r poc-8.ethdev.com -p 30303 -m off -j if [ -f /usr/bin/ethereum ]
then
ethereum -rpc true -rpcport 8080
else
eth -x 15 -l 30303 -r poc-8.ethdev.com -p 30303 -m off -j
fi

View File

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

View File

@ -9,7 +9,7 @@
}, },
"dependencies": { "dependencies": {
"debug": "~2.1.1", "debug": "~2.1.1",
"ethereum.js": "*", "ethereum.js": "0.1.*",
"lodash": "^3.2.0", "lodash": "^3.2.0",
"primus": "^2.4.12", "primus": "^2.4.12",
"primus-emit": "^0.1.2", "primus-emit": "^0.1.2",

View File

@ -1,38 +0,0 @@
[
{
"name" : "eth-go",
"cwd" : "/home/ubuntu/bin/www/",
"script" : "bin/eth-go.sh",
"log_file" : "/home/ubuntu/logs/eth-log.log",
"out_file" : "/home/ubuntu/logs/eth-out.log",
"error_file" : "/home/ubuntu/logs/eth-err.log",
"merge_logs" : true,
"watch" : false,
"cron_restart" : "0 0 * * *",
"exec_interpreter" : "bash",
"exec_mode" : "fork_mode"
},
{
"name" : "node-app",
"cwd" : "/home/ubuntu/bin/www/",
"script" : "app.js",
"log_file" : "/home/ubuntu/logs/node-app-log.log",
"out_file" : "/home/ubuntu/logs/node-app-out.log",
"error_file" : "/home/ubuntu/logs/node-app-err.log",
"merge_logs" : true,
"watch" : false,
"cron_restart" : "0 0 * * *",
"exec_interpreter" : "node",
"exec_mode" : "fork_mode",
"env":
{
"NODE_ENV" : "production",
"RPC_HOST" : "localhost",
"RPC_PORT" : "8080",
"ETH_IMPLEMENTATION" : "go",
"INSTANCE_NAME" : "",
"WS_SERVER" : "wss://eth-netstats.herokuapp.com",
"WS_SECRET" : "eth-net-stats-has-a-secret",
}
}
]

View File

@ -29,7 +29,6 @@
"NODE_ENV" : "production", "NODE_ENV" : "production",
"RPC_HOST" : "localhost", "RPC_HOST" : "localhost",
"RPC_PORT" : "8080", "RPC_PORT" : "8080",
"ETH_IMPLEMENTATION" : "cpp",
"INSTANCE_NAME" : "", "INSTANCE_NAME" : "",
"WS_SERVER" : "wss://eth-netstats.herokuapp.com", "WS_SERVER" : "wss://eth-netstats.herokuapp.com",
"WS_SECRET" : "eth-net-stats-has-a-secret", "WS_SECRET" : "eth-net-stats-has-a-secret",