forked from ajmachado/Udacity-Private-Blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (33 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//App file
//Import Classes Block and Blockchain
const Block = require('./simpleChain.js');
const Blockchain = require('./simpleChain.js');
//Create new blockchain
const myBlockChain = new Blockchain.Blockchain();
//Adding Blocks to chain
(function theLoop (i) {
setTimeout(function () {
let blockTest = new Block.Block("Test Block - " + (i + 1));
myBlockChain.addBlock(blockTest).then((result) => {
//console.log(result);
i++;
if (i < 12) theLoop(i);
});
}, 200);
})(0);
//Read the chain
setTimeout(function () {
console.log("Reading Blockchain...");
myBlockChain.chain.readChain();
},5000);
//Validate Chain
setTimeout(function () {
console.log("Validating Blockchain...");
myBlockChain.validateChain().then((result) => {
if(result == true){
console.log ("The Blockchain is validated without errors.");
}else {
console.log ("Errors in Blockchain validation.");
}
});
},8000);