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
5 changes: 5 additions & 0 deletions arrayofblocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var getGenesisBlock = () => {
return new Block(0, "0", 1465154705, "my block!!", "816534932c2b7154836da6afc367695e6337db8a921823784c14378abed4f7d7");
};

var blockchain = [getGenesisBlock()];
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();
}
}
3 changes: 3 additions & 0 deletions calHash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var calHash = (index, previousHash, timestamp, data) => {
return CryptoJS.SHA256(index + previousHash + timestamp + data).toString();
};
7 changes: 7 additions & 0 deletions generateNextblock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var generateNextBlock = (blockData) => {
var previousBlock = getLatestBlock();
var nextIndex = previousBlock.index + 1;
var nextTimestamp = new Date().getTime() / 1000;
var nextHash = calculateHash(nextIndex, previousBlock.hash, nextTimestamp, blockData);
return new Block(nextIndex, previousBlock.hash, nextTimestamp, blockData, nextHash);
};
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"
}
}
28 changes: 28 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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!");
});