Esempio n. 1
0
        public async Task ExecuteCashinCompleted(CoinEventCashinCompletedMessage message, QueueTriggeringContext context)
        {
            try
            {
                if (message == null || string.IsNullOrEmpty(message.TransactionHash))
                {
                    context.MoveMessageToPoison(message?.ToJson());
                }

                var coinEvent = await _coinEventService.GetCoinEvent(message.TransactionHash);

                if (coinEvent == null)
                {
                    return;
                }

                if (coinEvent.CoinEventType == CoinEventType.CashinStarted)
                {
                    await _coinTransactionService.PutTransactionToQueue(coinEvent.TransactionHash, coinEvent.OperationId);
                }
            }
            catch (Exception ex)
            {
                await _log.WriteErrorAsync("MonitoringCoinTransactionJob", "Execute", "", ex);

                if (message.DequeueCount > 10000)
                {
                    context.MoveMessageToPoison(message.ToJson());
                    return;
                }

                context.MoveMessageToEnd(message.ToJson());
                context.SetCountQueueBasedDelay(_settings.MaxQueueDelay, 150);
            }
        }
Esempio n. 2
0
        private async Task <ICoinEvent> GetCoinEvent(string transactionHash, string operationId, bool success)
        {
            var pendingOp = await _pendingOperationService.GetOperationByHashAsync(transactionHash);

            string opIdToSearch = pendingOp?.OperationId ?? operationId;
            var    coinEvent    = !string.IsNullOrEmpty(opIdToSearch) ?
                                  await _coinEventService.GetCoinEventById(opIdToSearch) : await _coinEventService.GetCoinEvent(transactionHash);

            coinEvent = coinEvent ?? await _coinEventService.GetCoinEvent(transactionHash);

            coinEvent.Success         = success;
            coinEvent.TransactionHash = transactionHash;

            return(coinEvent);
        }
        //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);
            }
        }