/// <summary> /// Adds a new block to the blockchain. /// If the block and it's hash matches other blocks already in the chain /// returns true otherwise returns false indicating that the block may be corrupted and can't be added /// </summary> /// <param name="content">The content of the new block</param> /// <param name="hash">The hash of the new block Indicating that the block is sound</param> /// <returns>True if the block is OK and added to chain or False if it's not</returns> public bool AddBlock(TContent content, THash hash) { var previous = store.GetLast(); if (previous == null) { AddGenesis(content); return(true); } //TODO This shouldn't get the previous hash but rather compute the hash all the way down to // genesis block. Or at least this should go a few (customizable number of) blocks down. var block = BlockFactory.Create(content, previous.Hash, cryptographyHelper); if (cryptographyHelper.CompareHash(hash, block.Hash)) { store.Insert(block); return(true); } return(false); }