public bool isChainValid() { for (int i = 1; i < this.chain.Count; i++) { Block currentBlock = this.chain[i]; Block previousBlock = this.chain[i - 1]; //Compare the two hashes for verification if (currentBlock.hash.Length == currentBlock.calculateHash().Length) { for (int ii = 0; ii < currentBlock.hash.Length; ii++) { //return false if a value doesn't match if (currentBlock.hash[ii] != currentBlock.calculateHash()[ii]) { return(false); } } } else { return(false); } //Compare the two hashes for verification if (currentBlock.previousHash.Length == previousBlock.hash.Length) { for (int ii = 0; ii < currentBlock.previousHash.Length; ii++) { //return false if a value doesn't match if (currentBlock.previousHash[ii] != previousBlock.hash[ii]) { return(false); } } } else { return(false); } } return(true); }
public void addBlock(Block newBlock) { newBlock.previousHash = this.getLatestBlock().hash; newBlock.hash = newBlock.calculateHash(); this.chain.Add(newBlock); }