//return whether we have sent to rabbit or not private async Task <bool> SendCompletedCoinEvent(string transactionHash, string operationId, bool success, QueueTriggeringContext context, CoinTransactionMessage transaction) { try { ICoinEvent coinEvent = await GetCoinEvent(transactionHash, operationId, success); switch (coinEvent.CoinEventType) { case CoinEventType.CashinStarted: ICashinEvent cashinEvent = await _transactionEventsService.GetCashinEvent(transactionHash); if (cashinEvent == null) { SendMessageToTheQueueEnd(context, transaction, 100); return(false); } //transferContract - userAddress await UpdateUserTransferWallet(coinEvent.FromAddress, coinEvent.ToAddress.ToLower()); coinEvent.Amount = cashinEvent.Amount; coinEvent.CoinEventType++; break; case CoinEventType.CashoutStarted: case CoinEventType.TransferStarted: //Say that Event Is completed coinEvent.CoinEventType++; break; default: break; } await _coinEventService.PublishEvent(coinEvent, putInProcessingQueue : false); await _pendingTransactionsRepository.Delete(transactionHash); await _pendingOperationService.MatchHashToOpId(transactionHash, coinEvent.OperationId); return(true); } catch (Exception e) { await _log.WriteErrorAsync("MonitoringCoinTransactionJob", "SendCompletedCoinEvent", $"trHash: {transactionHash}", e, DateTime.UtcNow); SendMessageToTheQueueEnd(context, transaction, 100); return(false); } }
//return whether we have sent to rabbit or not private async Task <bool> SendCompletedCoinEvent(string transactionHash, string operationId, bool success, QueueTriggeringContext context, CoinTransactionMessage transaction) { try { ICoinEvent coinEvent = await GetCoinEvent(transactionHash, operationId, success); switch (coinEvent.CoinEventType) { case CoinEventType.CashinStarted: ICashinEvent cashinEvent = await _transactionEventsService.GetCashinEvent(transactionHash); if (cashinEvent == null) { await _transactionEventsService.IndexEventsForTransaction(coinEvent.ContractAddress, transactionHash); SendMessageToTheQueueEnd(context, transaction, 100); return(false); } //transferContract - userAddress await UpdateUserTransferWallet(coinEvent.FromAddress, coinEvent.ToAddress.ToLower()); coinEvent.Amount = cashinEvent.Amount; coinEvent.CoinEventType++; break; case CoinEventType.CashoutStarted: case CoinEventType.TransferStarted: //Say that Event Is completed coinEvent.CoinEventType++; break; default: break; } #region FailedCashout if (coinEvent.CoinEventType == CoinEventType.CashoutCompleted && !success) { coinEvent.CoinEventType = CoinEventType.CashoutFailed; await _coinEventService.InsertAsync(coinEvent); SendMessageToTheQueueEnd(context, transaction, 200, "Put Failed cashout in the end of the queue"); return(false); } if (coinEvent.CoinEventType == CoinEventType.CashoutFailed && !success) { var historycal = await _pendingOperationService.GetHistoricalAsync(operationId); if (historycal != null) { foreach (var match in historycal) { if (!string.IsNullOrEmpty(match.TransactionHash) && await _ethereumTransactionService.IsTransactionExecuted(match.TransactionHash, Constants.GasForCoinTransaction)) { var @event = await _coinEventService.GetCoinEvent(match.TransactionHash); if (@event != null && @event.TransactionHash.ToLower() == match.TransactionHash.ToLower()) { await _slackNotifier.ErrorAsync($"EthereumCoreService: Transaction with hash {coinEvent.TransactionHash} [{coinEvent.OperationId}]" + $" ({coinEvent.CoinEventType}). Previously was successfully transfered"); return(false); } } } } } #endregion await _coinEventService.PublishEvent(coinEvent, putInProcessingQueue : false); await _pendingTransactionsRepository.Delete(transactionHash); await _pendingOperationService.MatchHashToOpId(transactionHash, coinEvent.OperationId); return(true); } catch (Exception e) { await _log.WriteErrorAsync("MonitoringCoinTransactionJob", "SendCompletedCoinEvent", $"trHash: {transactionHash}", e, DateTime.UtcNow); SendMessageToTheQueueEnd(context, transaction, 100); return(false); } }