private async Task ProcessHotWalletCashout(ProcessHotWalletErc20EventCommand queueMessage) { string transactionId = queueMessage.OperationId; CashOutContextData context = await _transactionService.GetTransactionContext <CashOutContextData>(transactionId); if (context == null) { _log.Error(new NullReferenceException("Context is null for hotwallet cashout"), context: queueMessage.ToJson()); return; } string clientId = context.ClientId; string hash = queueMessage.TransactionHash; string cashOperationId = context.CashOperationId; var clientAcc = await _clientAccountClient.GetByIdAsync(clientId); var clientEmail = await _personalDataService.GetEmailAsync(clientId); await _cashOperationsRepositoryClient.UpdateBlockchainHashAsync(clientId, cashOperationId, hash); await _srvEmailsFacade.SendNoRefundOCashOutMail(clientAcc.PartnerId, clientEmail, context.Amount, context.AssetId, hash); }
public async Task GenerateOrdinaryCashOut(string clientId, string address, double amount, string assetId, string privateKey) { var asset = await _assetsRepository.GetAssetAsync(assetId); if (asset == null) { return; } CashOutContextData contextData = null; try { var walletCredentials = await _walletCredentialsRepository.GetAsync(clientId); var cashOpId = await _cashOperationsRepository.RegisterAsync(new CashInOutOperation { Id = Guid.NewGuid().ToString("N"), ClientId = clientId, Multisig = walletCredentials.MultiSig, AssetId = assetId, Amount = -Math.Abs(amount), DateTime = DateTime.UtcNow, AddressFrom = walletCredentials.MultiSig, AddressTo = address }); var transactionId = Guid.NewGuid().ToString("N"); contextData = CashOutContextData.Create(clientId, assetId, address, amount, cashOpId); await _bitCoinTransactionsRepository.CreateAsync(transactionId, BitCoinCommands.OrdinaryCashOut, contextData); await _matchingEngineConnector.CashInOutBalanceAsync(contextData.ClientId, contextData.AssetId, -Math.Abs(amount), false, cashOpId); string request; if (_baseSettings.UsePushPrivateKeyService) { await _srvBlockchainHelper.PushPrivateKey(privateKey); request = await _bitCoinCommandProducer.ProduceOrdinaryCashOutCommand(transactionId, walletCredentials.MultiSig, amount, asset.BlockChainId, address); } else //ToDo: Temporary. Remove, when will be ready in ME { request = await _bitCoinCommandProducer.ObsoleteProduceOrdinaryCashOutCommand(transactionId, walletCredentials.MultiSig, amount, asset.BlockChainId, privateKey, address); } await _bitCoinTransactionsRepository.UpdateRequestAsync(transactionId, request); } catch (Exception ex) { await _log.WriteErrorAsync("SrvBitcoinCommandProducer", "OrdinaryCashOut", contextData?.ToJson(), ex); } }
private async Task ProcessOutcomeOperation(ProcessEthCoinEventCommand queueMessage) { var transferTx = await _ethereumTransactionRequestRepository.GetAsync(Guid.Parse(queueMessage.OperationId)); CashOutContextData context = await _transactionService.GetTransactionContext <CashOutContextData>(queueMessage.OperationId); if (transferTx != null) { switch (transferTx.OperationType) { case OperationType.CashOut: await SetCashoutHashes(transferTx, queueMessage.TransactionHash); break; case OperationType.Trade: await SetTradeHashes(transferTx, queueMessage.TransactionHash); break; case OperationType.TransferToTrusted: case OperationType.TransferFromTrusted: await SetTransferHashes(transferTx, queueMessage.TransactionHash); break; } ChaosKitty.Meow(); return; } if (context == null) { return; } string clientId = context.ClientId; string hash = queueMessage.TransactionHash; string cashOperationId = context.CashOperationId; var clientAcc = await _clientAccountClient.GetByIdAsync(clientId); var clientEmail = await _personalDataService.GetEmailAsync(clientId); await _cashOperationsRepositoryClient.UpdateBlockchainHashAsync(clientId, cashOperationId, hash); await _srvEmailsFacade.SendNoRefundOCashOutMail(clientAcc.PartnerId, clientEmail, context.Amount, context.AssetId, hash); ChaosKitty.Meow(); }
//TODO: Split wth the help of the process management private async Task ProcessFailedCashout(ProcessEthCoinEventCommand queueMessage) { CashOutContextData context = await _transactionService.GetTransactionContext <CashOutContextData>(queueMessage.OperationId); if (context != null) { string transactionHandlerUserId = "auto redeem"; string clientId = context.ClientId; string hash = queueMessage.TransactionHash; string cashOperationId = context.CashOperationId; string assetId = context.AssetId; var amount = context.Amount; try { ChaosKitty.Meow(); var asset = await _assetsService.AssetGetAsync(assetId); await _cashOperationsRepositoryClient.UpdateBlockchainHashAsync(clientId, cashOperationId, hash); var pt = await _paymentTransactionsRepository.TryCreateAsync(PaymentTransaction.Create(hash, CashInPaymentSystem.Ethereum, clientId, (double)amount, asset.DisplayId ?? asset.Id, status: PaymentStatus.Processing)); if (pt == null) { _log.Warning($"{nameof(EthereumCoreCommandHandler)}:{nameof(ProcessFailedCashout)}", "Transaction already handled", context: hash); return; //if was handled previously } ChaosKitty.Meow(); var sign = "+"; var commentText = $"Balance Update: {sign}{amount} {asset.Name}. Cashout failed: {hash} {queueMessage.OperationId}"; var newComment = new ClientComment { ClientId = clientId, Comment = commentText, CreatedAt = DateTime.UtcNow, FullName = "Lykke.Job.TransactionHandler", UserId = transactionHandlerUserId }; var exResult = await _exchangeOperationsServiceClient.ExchangeOperations.ManualCashInAsync( new ManualCashInRequestModel { ClientId = clientId, AssetId = assetId, Amount = (double)amount, UserId = "auto redeem", Comment = commentText, }); if (!exResult.IsOk()) { _log.Warning($"{nameof(EthereumCoreCommandHandler)}:{nameof(ProcessFailedCashout)}", "ME operation failed", context: new { ExchangeServiceResponse = exResult, QueueMessage = queueMessage }.ToJson()); } await _clientCommentsRepository.AddClientCommentAsync(newComment); await _paymentTransactionsRepository.SetStatus(hash, PaymentStatus.NotifyProcessed); ChaosKitty.Meow(); } catch (Exception e) { _log.Error($"{nameof(EthereumCoreCommandHandler)}:{nameof(ProcessFailedCashout)}", e, context: queueMessage.ToJson()); throw; } } else { _log.Warning("Can't get a context", context: queueMessage.ToJson()); } }