public async Task <IEnumerable <Transaction> > ProcessTransactionsAsync() { var transactionsToProcess = await DumpTransactionsToDbAsync(); var processingFailedTransactions = new List <Transaction>(); foreach (var transaction in transactionsToProcess) { var processingResult = await ProcessSingleTransactionAsync(transaction); if (processingResult is null) { processingFailedTransactions.Add(transaction); } else { await MarkTransactionAsProcessedAsync(transaction); } } IEnumerable <string> GetProcessedIdsByAdapterName(string adapterName) => transactionsToProcess.Where(x => processingFailedTransactions.All(y => y.TxKey != x.TxKey) && x.Symbol == adapterName) .Select(x => x.TxKey); var ethProcessedIds = GetProcessedIdsByAdapterName("ETH"); await _adapterApiService.MarkTransactionAsConfirmed(ethProcessedIds, "ETH"); var btcProcessedIds = GetProcessedIdsByAdapterName("BTC"); await _adapterApiService.MarkTransactionAsConfirmed(btcProcessedIds, "BTC"); return(processingFailedTransactions); }