Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Block {
constructor(index, previousHash, timestamp, data, hash) {
this.index = index;
this.previousHash = previousHash.toString();
this.timestamp = timestamp;
this.data = data;
this.hash = hash.toString();
}
}
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@
"lite-server": "^2.3.0"
}
}
"dependencies": {
"body-parser": "~1.10.2",
"cookie-parser": "~1.3.3",
"debug": "~2.1.1",
"express": "~4.11.1",
"jade": "~1.9.1",
"morgan": "~1.5.1",
"serve-favicon": "~2.2.0"
}
}
29 changes: 29 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var formidable = require('formidable'),
util = require('util'),
express = require('express'),

fs = require('fs'),
app = express();
app.use(express.static(__dirname, '/public'));
app.post('/upload', function(req, res) {
var form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files) {
// console.log(util.inspect({
// fields: fields,
// files: files
// }));

fs.readFile(files.RemoteFile.path, function(err, data) {
// save file from temp dir to new dir
var newPath = __dirname + "/uploads/" + files.RemoteFile.name;
fs.writeFile(newPath, data, function(err) {
if (err) throw err;
console.log('file saved');
res.end();
});
});
});
});
app.listen(process.env.PORT, process.env.IP, function(){
console.log("The Blockchain Server Has Started!");
});
13 changes: 13 additions & 0 deletions validatenewblock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var isValidNewBlock = (newBlock, previousBlock) => {
if (previousBlock.index + 1 !== newBlock.index) {
console.log('invalid index');
return false;
} else if (previousBlock.hash !== newBlock.previousHash) {
console.log('previous hash was invalid');
return false;
} else if (calculateHashForBlock(newBlock) !== newBlock.hash) {
console.log('invalid hash: ' + calculateHashForBlock(newBlock) + ' ' + newBlock.hash);
return false;
}
return true;
};