public async Task <bool> DeleteBlock([FromBody] BuddyLookup lookupData) { bool delete_status = await blockRepository.Delete(lookupData); if (delete_status) { var from_profile = (await profileRepository.Lookup(lookupData.SourceProfile)).First(); var to_profile = (await profileRepository.Lookup(lookupData.TargetProfile)).First(); blockRepository.SendDeleteEvent(from_profile, to_profile); } return(delete_status); }
public void BlockRepositoryPutBatch() { using (var blockRepository = new BlockRepository(this.network, TestBase.CreateDataFolder(this), this.loggerFactory, this.dBreezeSerializer)) { blockRepository.SetTxIndex(true); var blocks = new List <Block>(); for (int i = 0; i < 5; i++) { Block block = this.network.CreateBlock(); block.AddTransaction(this.network.CreateTransaction()); block.AddTransaction(this.network.CreateTransaction()); block.AddTransaction(this.network.CreateTransaction()); block.Transactions[0].AddInput(new TxIn(Script.Empty)); block.Transactions[0].AddOutput(Money.COIN + i * 2, Script.Empty); block.Transactions[1].AddInput(new TxIn(Script.Empty)); block.Transactions[1].AddOutput(Money.COIN + i * 2 + 1, Script.Empty); block.Transactions[2].AddObject(new TxObj(Money.COIN + i * 2 + 1, Script.Empty)); block.UpdateMerkleRoot(); block.Header.HashPrevBlock = blocks.Any() ? blocks.Last().GetHash() : this.network.GenesisHash; blocks.Add(block); } // put blockRepository.PutBlocks(new HashHeightPair(blocks.Last().GetHash(), blocks.Count), blocks); // check the presence of each block in the repository foreach (Block block in blocks) { Block received = blockRepository.GetBlock(block.GetHash()); Assert.True(block.ToBytes().SequenceEqual(received.ToBytes())); foreach (Transaction transaction in block.Transactions) { Transaction trx = blockRepository.GetTransactionById(transaction.GetHash()); Assert.True(trx.ToBytes().SequenceEqual(transaction.ToBytes())); } } // delete blockRepository.Delete(new HashHeightPair(blocks.ElementAt(2).GetHash(), 2), new[] { blocks.ElementAt(2).GetHash() }.ToList()); Block deleted = blockRepository.GetBlock(blocks.ElementAt(2).GetHash()); Assert.Null(deleted); } }