public IEnumerable <Tuple <ChainedBlock, Block> > PreviousBlocksLookAhead(ChainedBlock firstBlock) { using (var cancelToken = new CancellationTokenSource()) { foreach (var tuple in LookAheadMethods.LookAhead(() => PreviousBlocks(firstBlock), cancelToken.Token)) { yield return(tuple); } } }
public IEnumerable <Tuple <Block, ChainedBlock> > BlockLookAhead(IList <UInt256> blockHashes) { var blockLookAhead = LookAheadMethods.LookAhead( () => blockHashes.Select(blockHash => this.CacheContext.GetBlock(blockHash, saveInCache: false)), this.shutdownToken); var chainedBlockLookAhead = LookAheadMethods.LookAhead( () => blockHashes.Select(blockHash => this.CacheContext.GetChainedBlock(blockHash, saveInCache: false)), this.shutdownToken); return(blockLookAhead.Zip(chainedBlockLookAhead, (block, chainedBlock) => Tuple.Create(block, chainedBlock))); }
public IEnumerable <Tuple <Block, ChainedBlock /*, ImmutableDictionary<UInt256, Transaction>*/> > BlockAndTxLookAhead(IList <UInt256> blockHashes) { var blockLookAhead = LookAheadMethods.LookAhead( () => blockHashes.Select( blockHash => { var block = new MethodTimer(false).Time("GetBlock", () => this.CacheContext.GetBlock(blockHash, saveInCache: false)); this.CacheContext.TransactionCache.CacheBlock(block); //var transactionsBuilder = ImmutableDictionary.CreateBuilder<UInt256, Transaction>(); //var inputTxHashList = block.Transactions.Skip(1).SelectMany(x => x.Inputs).Select(x => x.PreviousTxOutputKey.TxHash).Distinct(); //// pre-cache input transactions ////Parallel.ForEach(inputTxHashList, inputTxHash => //foreach (var inputTxHash in inputTxHashList) //{ // Transaction inputTx; // if (this.CacheContext.TransactionCache.TryGetValue(inputTxHash, out inputTx, saveInCache: false)) // { // transactionsBuilder.Add(inputTxHash, inputTx); // } //} //return Tuple.Create(block, transactionsBuilder.ToImmutable()); return(block); }), this.shutdownToken); var chainedBlockLookAhead = LookAheadMethods.LookAhead( () => blockHashes.Select(blockHash => this.CacheContext.GetChainedBlock(blockHash, saveInCache: false)), this.shutdownToken); return(blockLookAhead.Zip(chainedBlockLookAhead, (block, chainedBlock) => Tuple.Create(block, chainedBlock))); }