Skip to content

Commit 92f19ce

Browse files
committed
initial import
1 parent 6602dab commit 92f19ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1683
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*~
2+
.*~
3+
node_modules/
4+
tools/runkeeper/

app.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
var express = require('express');
2+
var path = require('path');
3+
var favicon = require('serve-favicon');
4+
var logger = require('morgan');
5+
var cookieParser = require('cookie-parser');
6+
var bodyParser = require('body-parser');
7+
8+
var routes = require('./routes/index');
9+
10+
var app = express();
11+
12+
// view engine setup
13+
app.set('views', path.join(__dirname, 'views'));
14+
app.set('view engine', 'jade');
15+
16+
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
17+
app.use(logger('dev'));
18+
app.use(bodyParser.json());
19+
app.use(bodyParser.urlencoded({ extended: false }));
20+
app.use(cookieParser());
21+
app.use(express.static(path.join(__dirname, 'public')));
22+
23+
app.use('/', routes);
24+
25+
// catch 404 and forward to error handler
26+
app.use(function(req, res, next) {
27+
var err = new Error('Not Found');
28+
err.status = 404;
29+
next(err);
30+
});
31+
32+
// error handlers
33+
34+
// development error handler
35+
// will print stacktrace
36+
if (app.get('env') === 'development') {
37+
app.use(function(err, req, res, next) {
38+
res.status(err.status || 500);
39+
res.render('error', {
40+
message: err.message,
41+
error: err
42+
});
43+
});
44+
}
45+
46+
// production error handler
47+
// no stacktraces leaked to user
48+
app.use(function(err, req, res, next) {
49+
res.status(err.status || 500);
50+
res.render('error', {
51+
message: err.message,
52+
error: {}
53+
});
54+
});
55+
56+
57+
module.exports = app;

bin/www

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var app = require('../app');
8+
var debug = require('debug')('zurveys:server');
9+
var http = require('http');
10+
11+
/**
12+
* Get port from environment and store in Express.
13+
*/
14+
15+
var port = normalizePort(process.env.PORT || '3000');
16+
app.set('port', port);
17+
18+
/**
19+
* Create HTTP server.
20+
*/
21+
22+
var server = http.createServer(app);
23+
24+
/**
25+
* Listen on provided port, on all network interfaces.
26+
*/
27+
28+
server.listen(port);
29+
server.on('error', onError);
30+
server.on('listening', onListening);
31+
32+
/**
33+
* Normalize a port into a number, string, or false.
34+
*/
35+
36+
function normalizePort(val) {
37+
var port = parseInt(val, 10);
38+
39+
if (isNaN(port)) {
40+
// named pipe
41+
return val;
42+
}
43+
44+
if (port >= 0) {
45+
// port number
46+
return port;
47+
}
48+
49+
return false;
50+
}
51+
52+
/**
53+
* Event listener for HTTP server "error" event.
54+
*/
55+
56+
function onError(error) {
57+
if (error.syscall !== 'listen') {
58+
throw error;
59+
}
60+
61+
var bind = typeof port === 'string'
62+
? 'Pipe ' + port
63+
: 'Port ' + port;
64+
65+
// handle specific listen errors with friendly messages
66+
switch (error.code) {
67+
case 'EACCES':
68+
console.error(bind + ' requires elevated privileges');
69+
process.exit(1);
70+
break;
71+
case 'EADDRINUSE':
72+
console.error(bind + ' is already in use');
73+
process.exit(1);
74+
break;
75+
default:
76+
throw error;
77+
}
78+
}
79+
80+
/**
81+
* Event listener for HTTP server "listening" event.
82+
*/
83+
84+
function onListening() {
85+
var addr = server.address();
86+
var bind = typeof addr === 'string'
87+
? 'pipe ' + addr
88+
: 'port ' + addr.port;
89+
debug('Listening on ' + bind);
90+
}

package.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "blockchain-demo",
3+
"description": "A web-based demonstration of blockchain concepts.",
4+
"author": {
5+
"name": "Anders Brownworth"
6+
},
7+
"version": "0.0.1",
8+
"keywords": [
9+
"blockchain",
10+
"demo",
11+
"bitcoin"
12+
],
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/anders94/blockchain-demo.git"
16+
},
17+
"bugs": {
18+
"url": "https://github.com/anders94/blockchain-demo/issues"
19+
},
20+
"license": "MIT",
21+
"devDependencies": {
22+
"async": "^1.4.2",
23+
"express": "^4.13.4"
24+
},
25+
"homepage": "https://github.com/anders94/blockchain-demo#readme",
26+
"maintainers": [
27+
{
28+
"name": "anders",
29+
"email": "[email protected]"
30+
}
31+
]
32+
}

public/favicon.ico

3.55 KB
Binary file not shown.
19.7 KB
Binary file not shown.

public/fonts/glyphicons-halflings-regular.svg

+288
Loading
44.3 KB
Binary file not shown.
22.9 KB
Binary file not shown.
17.6 KB
Binary file not shown.
10.8 KB
Loading
6.02 KB
Loading

public/javascripts/blockchain.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
function sha256(block, chain) {
2+
// calculate a SHA256 hash of the contents of the block
3+
return CryptoJS.SHA256(getText(block, chain));
4+
}
5+
6+
function updateState(block, chain) {
7+
// set the well background red or green for this block
8+
if ($('#block'+block+'chain'+chain+'hash').val().substr(0, 4) === '0000') {
9+
$('#block'+block+'chain'+chain+'well').removeClass('well-error').addClass('well-success');
10+
}
11+
else {
12+
$('#block'+block+'chain'+chain+'well').removeClass('well-success').addClass('well-error');
13+
}
14+
}
15+
16+
function updateHash(block, chain) {
17+
// update the SHA256 hash value for this block
18+
$('#block'+block+'chain'+chain+'hash').val(sha256(block, chain));
19+
updateState(block, chain);
20+
}
21+
22+
function updateChain(block, chain) {
23+
// update all blocks walking the chain from this block to the end
24+
for (var x = block; x <= 5; x++) {
25+
if (x > 1) {
26+
$('#block'+x+'chain'+chain+'previous').val($('#block'+(x-1).toString()+'chain'+chain+'hash').val());
27+
}
28+
updateHash(x, chain);
29+
}
30+
}
31+
32+
function mine(block, chain, isChain) {
33+
var found = false;
34+
for (var x = 0; x <= 200000 && !found; x++) {
35+
$('#block'+block+'chain'+chain+'nonce').val(x);
36+
$('#block'+block+'chain'+chain+'hash').val(sha256(block, chain));
37+
if ($('#block'+block+'chain'+chain+'hash').val().substr(0, 4) === '0000') {
38+
found = true;
39+
if (isChain) {
40+
updateChain(block, chain);
41+
}
42+
else {
43+
updateState(block, chain);
44+
}
45+
}
46+
}
47+
}

public/javascripts/lib/bootstrap.min.js

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*!
2+
* IE10 viewport hack for Surface/desktop Windows 8 bug
3+
* Copyright 2014-2015 Twitter, Inc.
4+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
5+
*/
6+
7+
// See the Getting Started docs for more information:
8+
// http://getbootstrap.com/getting-started/#support-ie10-width
9+
10+
(function () {
11+
'use strict';
12+
13+
if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
14+
var msViewportStyle = document.createElement('style')
15+
msViewportStyle.appendChild(
16+
document.createTextNode(
17+
'@-ms-viewport{width:auto!important}'
18+
)
19+
)
20+
document.querySelector('head').appendChild(msViewportStyle)
21+
}
22+
23+
})();

public/javascripts/lib/jquery.min.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/javascripts/lib/ladda.min.js

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/javascripts/lib/sha256.js

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/javascripts/lib/spin.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/javascripts/lib/ui-bootstrap-0.9.0.min.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/javascripts/lib/ui-bootstrap-tpls-0.9.0.min.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

0 commit comments

Comments
 (0)