public BlockchainServices() { // generate initial blockchain with genesis block blockchain = new Blockchain(); // calculate hash of genesis block Block genesisBlock = blockchain.Chain[0]; BlockServices blockServices = new BlockServices(genesisBlock); string genesisBlockHash = blockServices.BlockHash(); blockchain.Chain[0].Hash = genesisBlockHash; }
public bool isBlockchainValid() { for (long i = 1; i < blockchain.Chain.LongCount(); i++) { Block currentBlock = blockchain.Chain[(int)i]; Block previousBlock = blockchain.Chain[(int)i - 1]; BlockServices blockServices = new BlockServices(currentBlock); if (currentBlock.Hash != blockServices.BlockHash()) { return(false); } if (currentBlock.PreviousHash != previousBlock.Hash) { return(false); } blockServices = null; } return(true); }