-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gobitlfy
committed
Mar 9, 2017
0 parents
commit 53ba805
Showing
28 changed files
with
1,955 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# Data directory | ||
data/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# etherchain-light |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
var express = require('express'); | ||
var path = require('path'); | ||
var favicon = require('serve-favicon'); | ||
var logger = require('morgan'); | ||
var cookieParser = require('cookie-parser'); | ||
var bodyParser = require('body-parser'); | ||
|
||
var index = require('./routes/index'); | ||
var block = require('./routes/block'); | ||
var tx = require('./routes/tx'); | ||
var account = require('./routes/account'); | ||
var contract = require('./routes/contract'); | ||
var search = require('./routes/search'); | ||
|
||
var config = require('./config.js'); | ||
|
||
var levelup = require('levelup'); | ||
var db = levelup('./data'); | ||
|
||
var app = express(); | ||
|
||
// view engine setup | ||
app.set('views', path.join(__dirname, 'views')); | ||
app.set('view engine', 'pug'); | ||
app.set('config', config); | ||
app.set('db', db); | ||
|
||
// uncomment after placing your favicon in /public | ||
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); | ||
app.use(logger('dev')); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ | ||
extended: false | ||
})); | ||
app.use(cookieParser()); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
app.locals.moment = require('moment'); | ||
app.locals.numeral = require('numeral'); | ||
app.locals.ethformatter = require('./utils/ethformatter.js'); | ||
app.locals.nameformatter = new(require('./utils/nameformatter.js'))(config); | ||
|
||
app.use('/', index); | ||
app.use('/block', block); | ||
app.use('/tx', tx); | ||
app.use('/account', account); | ||
app.use('/contract', contract); | ||
app.use('/search', search); | ||
|
||
// catch 404 and forward to error handler | ||
app.use(function(req, res, next) { | ||
var err = new Error('Not Found'); | ||
err.status = 404; | ||
next(err); | ||
}); | ||
|
||
// error handler | ||
app.use(function(err, req, res, next) { | ||
// set locals, only providing error in development | ||
res.locals.message = err.message; | ||
res.locals.error = req.app.get('env') === 'development' ? err : {}; | ||
|
||
// render the error page | ||
res.status(err.status || 500); | ||
res.render('error'); | ||
}); | ||
|
||
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var app = require('../app'); | ||
var debug = require('debug')('etherchain-light:server'); | ||
var http = require('http'); | ||
|
||
/** | ||
* Get port from environment and store in Express. | ||
*/ | ||
|
||
var port = normalizePort(process.env.PORT || '3000'); | ||
app.set('port', port); | ||
|
||
/** | ||
* Create HTTP server. | ||
*/ | ||
|
||
var server = http.createServer(app); | ||
|
||
/** | ||
* Listen on provided port, on all network interfaces. | ||
*/ | ||
|
||
server.listen(port); | ||
server.on('error', onError); | ||
server.on('listening', onListening); | ||
|
||
/** | ||
* Normalize a port into a number, string, or false. | ||
*/ | ||
|
||
function normalizePort(val) { | ||
var port = parseInt(val, 10); | ||
|
||
if (isNaN(port)) { | ||
// named pipe | ||
return val; | ||
} | ||
|
||
if (port >= 0) { | ||
// port number | ||
return port; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Event listener for HTTP server "error" event. | ||
*/ | ||
|
||
function onError(error) { | ||
if (error.syscall !== 'listen') { | ||
throw error; | ||
} | ||
|
||
var bind = typeof port === 'string' | ||
? 'Pipe ' + port | ||
: 'Port ' + port; | ||
|
||
// handle specific listen errors with friendly messages | ||
switch (error.code) { | ||
case 'EACCES': | ||
console.error(bind + ' requires elevated privileges'); | ||
process.exit(1); | ||
break; | ||
case 'EADDRINUSE': | ||
console.error(bind + ' is already in use'); | ||
process.exit(1); | ||
break; | ||
default: | ||
throw error; | ||
} | ||
} | ||
|
||
/** | ||
* Event listener for HTTP server "listening" event. | ||
*/ | ||
|
||
function onListening() { | ||
var addr = server.address(); | ||
var bind = typeof addr === 'string' | ||
? 'pipe ' + addr | ||
: 'port ' + addr.port; | ||
debug('Listening on ' + bind); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var config = { | ||
"backend": process.env["HOME"] + "/.local/share/io.parity.ethereum/jsonrpc.ipc", | ||
"names": { | ||
"0x007733a1fe69cf3f2cf989f81c7b4cac1693387a": "POA-Digix", | ||
"0x00e4a10650e5a6d6001c38ff8e64f97016a1645c": "POA-Aurel", | ||
"0x00e6d2b931f55a3f1701c7389d592a7778897879": "POA-Maker", | ||
"0x0010f94b296a852aaac52ea6c5ac72e03afd032d": "POA-Paritytech", | ||
"0x0020ee4be0e2027d76603cb751ee069519ba81a1": "POA-Melonport", | ||
"0x4ed9b08e6354c70fe6f8cb0411b0d3246b424d6c": "POA-OneBit", | ||
"0x00d6cc1ba9cf89bd2e58009741f4f7325badc0ed": "POA-Etherscan", | ||
"0x00a0a24b9f0e5ec7aa4c7389b8302fd0123194de": "POA-GridS", | ||
"0x00427feae2419c15b89d1c21af10d1b6650a4d3d": "POA-Attores" | ||
} | ||
} | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "etherchain-light", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"start": "node ./bin/www" | ||
}, | ||
"dependencies": { | ||
"async": "^2.1.5", | ||
"bignumber.js": "^4.0.0", | ||
"body-parser": "~1.16.0", | ||
"cookie-parser": "~1.4.3", | ||
"debug": "~2.6.0", | ||
"express": "~4.14.1", | ||
"level": "^1.6.0", | ||
"leveldown": "^1.6.0", | ||
"levelup": "^1.3.5", | ||
"moment": "^2.17.1", | ||
"morgan": "~1.7.0", | ||
"numeral": "^2.0.4", | ||
"pug": "~2.0.0-beta10", | ||
"serve-favicon": "~2.3.2", | ||
"solc": "^0.4.9", | ||
"string-similarity": "^1.1.0", | ||
"tmp": "0.0.31", | ||
"web3": "git+https://github.com/gobitfly/web3.js.git#develop", | ||
"yargs": "^7.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
body { | ||
padding: 50px; | ||
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; | ||
} | ||
|
||
a { | ||
color: #00B7FF; | ||
} | ||
|
||
.capitalize { | ||
text-transform:capitalize; | ||
} | ||
|
||
pre { | ||
white-space: pre-wrap; /* Since CSS 2.1 */ | ||
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ | ||
white-space: -pre-wrap; /* Opera 4-6 */ | ||
white-space: -o-pre-wrap; /* Opera 7 */ | ||
word-wrap: break-word; /* Internet Explorer 5.5+ */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
|
||
var async = require('async'); | ||
var Web3 = require('web3'); | ||
var net = require('net'); | ||
|
||
router.get('/:account', function(req, res, next) { | ||
|
||
var config = req.app.get('config'); | ||
var web3 = new Web3(); | ||
|
||
web3.setProvider(new web3.providers.IpcProvider(config.backend, require('net'))); | ||
|
||
var db = req.app.get('db'); | ||
|
||
var data = {}; | ||
|
||
async.waterfall([ | ||
function(callback) { | ||
web3.eth.getBlock("latest", false, function(err, result) { | ||
callback(err, result); | ||
}); | ||
}, function(lastBlock, callback) { | ||
data.lastBlock = lastBlock.number; | ||
web3.eth.getBalance(req.params.account, function(err, balance) { | ||
callback(err, balance); | ||
}); | ||
}, function(balance, callback) { | ||
data.balance = balance; | ||
web3.eth.getCode(req.params.account, function(err, code) { | ||
callback(err, code); | ||
}); | ||
}, function(code, callback) { | ||
data.code = code; | ||
if (code !== "0x") { | ||
data.isContract = true; | ||
} | ||
|
||
db.get(req.params.account.toLowerCase(), function(err, value) { | ||
callback(null, value); | ||
}); | ||
}, function(source, callback) { | ||
|
||
if (source) { | ||
data.source = JSON.parse(source); | ||
} | ||
|
||
web3.trace.filter({ "fromBlock": "0x00", "fromAddress": [ req.params.account ] }, function(err, traces) { | ||
callback(err, traces); | ||
}); | ||
}, function(tracesSent, callback) { | ||
data.tracesSent = tracesSent; | ||
web3.trace.filter({ "fromBlock": "0x00", "toAddress": [ req.params.account ] }, function(err, traces) { | ||
callback(err, traces); | ||
}); | ||
} | ||
], function(err, tracesReceived) { | ||
if (err) { | ||
return next(err); | ||
} | ||
|
||
data.address = req.params.account; | ||
data.tracesReceived = tracesReceived; | ||
|
||
var blocks = {}; | ||
data.tracesSent.forEach(function(trace) { | ||
if (!blocks[trace.blockNumber]) { | ||
blocks[trace.blockNumber] = []; | ||
} | ||
|
||
blocks[trace.blockNumber].push(trace); | ||
}); | ||
data.tracesReceived.forEach(function(trace) { | ||
if (!blocks[trace.blockNumber]) { | ||
blocks[trace.blockNumber] = []; | ||
} | ||
|
||
blocks[trace.blockNumber].push(trace); | ||
}); | ||
|
||
data.tracesSent = null; | ||
data.tracesReceived = null; | ||
|
||
data.blocks = []; | ||
var txCounter = 0; | ||
for (block in blocks) { | ||
data.blocks.push(blocks[block]); | ||
txCounter++; | ||
} | ||
|
||
if (data.source) { | ||
data.name = data.source.name; | ||
} else if (config.names[data.address]) { | ||
data.name = config.names[data.address]; | ||
} | ||
|
||
data.blocks = data.blocks.reverse().splice(0, 100); | ||
res.render('account', { account: data }); | ||
}); | ||
|
||
}); | ||
|
||
module.exports = router; |
Oops, something went wrong.