Created
March 30, 2018 22:48
-
-
Save cardeol/682f439d0a870f5e02b460fb4cb3f3fd to your computer and use it in GitHub Desktop.
Main algorithm blockchain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Blockchain = require("./blockchain.js"); | |
var Block = require("./block.js"); | |
var difficulty = 7; // number of zeroes in the hash key | |
var blockchain = new Blockchain(difficulty); | |
var currentBlock, prevBlock, genesisBlock; | |
(function Main() { | |
var i; // counter | |
genesisBlock = new Block("Hello Blockchain"); | |
for(i = 0; i <= 5; i++) { | |
currentBlock = (i == 0) ? genesisBlock : new Block("This is the block #" + i, prevBlock.getHash()); | |
console.log("Mining block #" + i); | |
currentBlock.mineBlock(difficulty); // mining block with the required difficulty | |
blockchain.add(currentBlock); // add mined block into the blockchain | |
prevBlock = currentBlock; | |
} | |
blockchain.checkDataIntegrity(); // check integrity | |
for(i = 0 ; i < blockchain.size(); i++) { | |
currentBlock = blockchain.get(i); | |
console.log("Block #" + i + " data: " + currentBlock.getData()); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment