diff --git a/app.js b/app.js index 3e4cebf..53bc5c8 100644 --- a/app.js +++ b/app.js @@ -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'))); diff --git a/config/nodes.js b/config/nodes.js new file mode 100644 index 0000000..1f1c559 --- /dev/null +++ b/config/nodes.js @@ -0,0 +1,10 @@ +var nodes = [ + { + nodeName: 'poc-7.ethdev.com', + rpcProvider: 'HttpRpcProvider', + rpcHost: '207.12.89.180', + rpcPort: '8080' + } +]; + +module.exports = nodes; diff --git a/models/node.js b/models/node.js new file mode 100644 index 0000000..d125ff6 --- /dev/null +++ b/models/node.js @@ -0,0 +1,6 @@ +var web3 = require('ethereum.js'); +var geoip = require('geoip-lite'); + +var Node = {}; + +module.exports = Node; \ No newline at end of file diff --git a/package.json b/package.json index 972afbd..ecc1d5c 100644 --- a/package.json +++ b/package.json @@ -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" } -} \ No newline at end of file +} diff --git a/routes/stats.js b/routes/stats.js index 18f0f41..6de843e 100644 --- a/routes/stats.js +++ b/routes/stats.js @@ -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) {