added eth js and geo

This commit is contained in:
Marian Oancea 2014-12-04 23:35:09 +02:00
parent 3054ad1921
commit 00fc14bad0
5 changed files with 48 additions and 7 deletions

4
app.js
View File

@ -2,12 +2,13 @@ var express = require('express.io');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var stats = require('./routes/stats');
require('es6-promise').polyfill();
express().http().io();
var app = express();
@ -21,7 +22,6 @@ app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(require('stylus').middleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));

10
config/nodes.js Normal file
View File

@ -0,0 +1,10 @@
var nodes = [
{
nodeName: 'poc-7.ethdev.com',
rpcProvider: 'HttpRpcProvider',
rpcHost: '207.12.89.180',
rpcPort: '8080'
}
];
module.exports = nodes;

6
models/node.js Normal file
View File

@ -0,0 +1,6 @@
var web3 = require('ethereum.js');
var geoip = require('geoip-lite');
var Node = {};
module.exports = Node;

View File

@ -6,13 +6,15 @@
"start": "node ./bin/www"
},
"dependencies": {
"express.io": "^1.1.13",
"body-parser": "~1.8.1",
"cookie-parser": "~1.3.3",
"debug": "~2.0.0",
"es6-promise": "*",
"ethereum.js": "*",
"express.io": "^1.1.13",
"geoip-lite": "^1.1.4",
"jade": "~1.6.0",
"morgan": "~1.3.0",
"serve-favicon": "~2.1.3",
"debug": "~2.0.0",
"jade": "~1.6.0",
"stylus": "0.42.3"
}
}

View File

@ -1,4 +1,27 @@
var router = require('express.io')();
var web3 = require('ethereum.js');
var geoip = require('geoip-lite');
var config = require('../config/nodes');
var geo = geoip.lookup(config[0].rpcHost);
console.log(geo);
if( ! web3.provider.installed()) {
var sock = new web3.providers[config[0].rpcProvider]((config[0].rpcProvider === 'HttpRpcProvider' ? 'http://' : 'ws://' ) + config[0].rpcHost + ':' + config[0].rpcPort);
web3.setProvider(sock);
}
web3.eth.mining.then(function(data){
console.log("is mining: " + data);
});
web3.eth.peerCount.then(function(data){
console.log("peers: " + data);§
});
web3.eth.number.then(function(data){
console.log("latest block: " + data);
});
/* GET stats listing. */
router.get('/', function(req, res) {