public void TestCaptureOrder() { // post source ints var intSource = new BufferBlock <int>(); intSource.Post(1); intSource.Post(2); intSource.Post(99); intSource.Post(98); intSource.Complete(); // capture source order var orderedInts = OrderingBlock.CaptureOrder <int, long, long>( intSource, intValue => (long)intValue); // post longs to combine, in reverse of original order var longSource = new BufferBlock <long>(); longSource.Post(99); longSource.Post(98); longSource.Post(2); longSource.Post(1); longSource.Complete(); // apply source order var orderedLongs = orderedInts.ApplyOrder(longSource, longValue => longValue); // verify the original order was preserved CollectionAssert.AreEqual(new long[] { 1, 2, 99, 98 }, orderedLongs.ToEnumerable().ToList()); }
public static ISourceBlock <DecodedBlockTx> LookAhead(ISourceBlock <DecodedBlockTx> blockTxes, IDeferredChainStateCursor deferredChainStateCursor, CancellationToken cancelToken = default(CancellationToken)) { // capture the original block txes order var orderedBlockTxes = OrderingBlock.CaptureOrder <DecodedBlockTx, DecodedBlockTx, int>( blockTxes, blockTx => blockTx.Index, cancelToken); // queue each utxo entry to be warmed up: each input's previous transaction, and each new transaction var queueUnspentTxLookup = InitQueueUnspentTxLookup(cancelToken); orderedBlockTxes.LinkTo(queueUnspentTxLookup, new DataflowLinkOptions { PropagateCompletion = true }); // warm up each uxto entry var warmupUtxo = InitWarmupUtxo(deferredChainStateCursor, cancelToken); queueUnspentTxLookup.LinkTo(warmupUtxo, new DataflowLinkOptions { PropagateCompletion = true }); // return the block txes with warmed utxo entries in original order return(orderedBlockTxes.ApplyOrder(warmupUtxo, blockTx => blockTx.Index, cancelToken)); }