-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (28 loc) · 808 Bytes
/
index.js
File metadata and controls
33 lines (28 loc) · 808 Bytes
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
let BlockChain = require('./BlockChain/blockChain')
require('dotenv').config();
let hash = require("object-hash")
let blockChain = new BlockChain();
//TO run the file: node index.js
let PROOF = Number(process.env.PROOF);
let validProof = (proof) => {
let guessHash = hash(proof);
console.log("Hashing guess:", guessHash)
return guessHash == hash(PROOF);
}
let proofOfWork = () => {
let proof = 0;
while (true) {
if (!validProof(proof)) {
proof++;
} else {
break;
}
}
return proof;
}
if (proofOfWork() == PROOF) {
blockChain.addNewTransaction("tom", 'john', 100);
let prevHash = blockChain.lastBlock() ? blockChain.lastBlock().hash : null;
blockChain.addNewBlock(prevHash);
}
console.log("chain:", blockChain.chain)