public void Add(int height, Block block) { foreach (var spk in TrackedScriptPubKeys) { TrackIfFindRelatedTransactions(spk, height, block); } FullBlockBuffer.AddOrReplace(height, block); HashSet <uint256> notFoundTransactions = GetNotYetFoundTrackedTransactions(); HashSet <uint256> foundTransactions = new HashSet <uint256>(); foreach (var txid in notFoundTransactions) { if (block.Transactions.Any(x => x.GetHash().Equals(txid))) { foundTransactions.Add(txid); } } MerkleBlock merkleProof = foundTransactions.Count == 0 ? block.Filter() : block.Filter(foundTransactions.ToArray()); var partialBlock = new PartialBlock(height, merkleProof); foreach (var txid in foundTransactions) { foreach (var tx in block.Transactions) { if (tx.GetHash().Equals(txid)) { partialBlock.Transactions.Add(tx); } } } Chain.AddOrReplace(partialBlock.Height, partialBlock); }
public void ReorgOne() { // remove the last block PartialBlock pb; if (Chain.Count != 0) { Chain.TryRemove(BestHeight, out pb); if (pb.Transactions.Count != 0) { // set the transactions to unconfirmed foreach (var txId in pb.Transactions.Select(x => x.GetHash())) { TrackedTransactions.AddOrReplace(txId, -1); } } } // remove the last block from the buffer too Block b; if (FullBlockBuffer.Count() != 0) { FullBlockBuffer.TryRemove(FullBlockBuffer.Keys.Max(), out b); } }