Example #1
0
        private IEnumerable <FilterLog> FilterLogsInBlockHighMemoryAllocation(LogFilter filter, Keccak blockHash, long blockNumber)
        {
            TxReceipt[] GetReceipts(Keccak hash, long number)
            {
                var canUseHash = _receiptFinder.CanGetReceiptsByHash(number);

                if (canUseHash)
                {
                    return(_receiptFinder.Get(hash));
                }
                else
                {
                    var block = _blockFinder.FindBlock(blockHash, BlockTreeLookupOptions.TotalDifficultyNotNeeded);
                    return(block == null ? null : _receiptFinder.Get(block));
                }
            }

            void RecoverReceiptsData(Keccak hash, TxReceipt[] receipts)
            {
                if (_receiptsRecovery.NeedRecover(receipts))
                {
                    var block = _blockFinder.FindBlock(hash, BlockTreeLookupOptions.TotalDifficultyNotNeeded);
                    if (block != null)
                    {
                        _receiptsRecovery.TryRecover(block, receipts);
                    }
                }
            }

            var  receipts        = GetReceipts(blockHash, blockNumber);
            long logIndexInBlock = 0;

            if (receipts != null)
            {
                for (var i = 0; i < receipts.Length; i++)
                {
                    var receipt = receipts[i];

                    if (filter.Matches(receipt.Bloom))
                    {
                        for (var j = 0; j < receipt.Logs.Length; j++)
                        {
                            var log = receipt.Logs[j];
                            if (filter.Accepts(log))
                            {
                                RecoverReceiptsData(blockHash, receipts);
                                yield return(new FilterLog(logIndexInBlock, j, receipt, log));
                            }

                            logIndexInBlock++;
                        }
                    }
                    else
                    {
                        logIndexInBlock += receipt.Logs.Length;
                    }
                }
            }
        }
        public TxReceipt[] Get(Keccak blockHash)
        {
            var receipts = _innerFinder.Get(blockHash);

            if (_receiptsRecovery.NeedRecover(receipts))
            {
                var block = _blockFinder.FindBlock(blockHash, BlockTreeLookupOptions.TotalDifficultyNotNeeded);
                _receiptsRecovery.TryRecover(block, receipts);
            }

            return(receipts);
        }
        public TxReceipt[] Get(Keccak blockHash)
        {
            var receipts = _receiptStorage.Get(blockHash);

            if (_receiptsRecovery.NeedRecover(receipts))
            {
                var block = _blockFinder.FindBlock(blockHash, BlockTreeLookupOptions.TotalDifficultyNotNeeded);
                if (_receiptsRecovery.TryRecover(block, receipts) == ReceiptsRecoveryResult.Success)
                {
                    _receiptStorage.Insert(block, receipts);
                }
            }

            return(receipts);
        }