public async Task <int> HandleTransactionsAsync(ITransaction[] transactions) { var blocks = transactions .GroupBy(t => new { t.BlockId, Currency = Enum.GetName(typeof(CurrencyType), t.Currency) }) .Select(g => g.Key); await _log.WriteInfoAsync(nameof(HandleTransactionsAsync), $"Transactions: {transactions.Length}, Blocks: {blocks.ToJson()}", $"Transactions processing started"); var count = 0; foreach (var tx in transactions) { var payInAddress = await _payInAddressRepository.GetAsync(tx.PayInAddress, tx.Currency); if (payInAddress == null) { // destination address is not a pay-in address of any ICO investor continue; } var campaignSettings = await _campaignSettingsRepository.GetCachedAsync(payInAddress.CampaignId, reloadIf : x => string.IsNullOrEmpty(x?.TransactionQueueSasUrl)); await _transactionRepository.EnqueueTransactionAsync(tx, payInAddress, campaignSettings.TransactionQueueSasUrl); await _log.WriteInfoAsync(nameof(HandleTransactionsAsync), $"Transaction: {tx.ToJson()}", $"Transaction sent to {payInAddress.CampaignId} queue"); count++; } await _log.WriteInfoAsync(nameof(HandleTransactionsAsync), $"Investments: {count}", $"Transactions processing completed"); return(count); }
public async Task <IActionResult> AddPayInAddress([FromBody] PayInAddressModel payInAddress) { if (!ModelState.IsValid) { return(BadRequest(ErrorResponseFactory.Create(ModelState))); } var entity = await _addressRepository.GetAsync(payInAddress.Address, payInAddress.Currency); if (entity != null) { return(StatusCode(StatusCodes.Status409Conflict, ErrorResponse.Create($"Pay-in address {payInAddress.Address} is already in use"))); } await _addressRepository.InsertAsync(payInAddress); await _log.WriteInfoAsync(nameof(AddPayInAddress), payInAddress.ToJson(), "Pay-in address added"); return(Ok()); }