public async Task <CommandHandlingResult> Handle(SaveEthInHistoryCommand command, IEventPublisher eventPublisher)
        {
            var sw = new Stopwatch();

            sw.Start();

            try
            {
                var cashinId      = command.CashinOperationId.ToString("N");
                var clientId      = command.ClientId;
                var hash          = command.TransactionHash;
                var amount        = command.Amount;
                var clientAddress = command.ClientAddress;

                await _cashOperationsRepositoryClient.RegisterAsync(new CashInOutOperation
                {
                    Id             = cashinId,
                    ClientId       = clientId.ToString(),
                    AssetId        = command.AssetId,
                    Amount         = (double)amount,
                    BlockChainHash = hash,
                    DateTime       = DateTime.UtcNow,
                    AddressTo      = clientAddress,
                    State          = TransactionStates.SettledOnchain
                });

                ChaosKitty.Meow();

                var clientAcc = await _clientAccountClient.GetByIdAsync(clientId.ToString());

                var clientEmail = await _personalDataService.GetEmailAsync(clientId.ToString());

                await _srvEmailsFacade.SendNoRefundDepositDoneMail(clientAcc.PartnerId, clientEmail, amount,
                                                                   command.AssetId);

                await _paymentTransactionsRepository.SetStatus(hash, PaymentStatus.NotifyProcessed);

                ChaosKitty.Meow();

                eventPublisher.PublishEvent(new EthCashinSavedInHistoryEvent()
                {
                    TransactionHash = hash
                });

                return(CommandHandlingResult.Ok());
            }
            catch (Exception e)
            {
                _log.Error(nameof(SaveEthInHistoryCommand), e, context: command);
                throw;
            }
            finally
            {
                sw.Stop();
                _log.Info("Command execution time",
                          context: new { TxHandler = new { Handler = nameof(EthereumCoreCommandHandler), Command = nameof(SaveEthInHistoryCommand),
                                                           Time    = sw.ElapsedMilliseconds } });
            }
        }
Exemple #2
0
        private async Task RegisterOperation(CashInOutOperation operation)
        {
            var operationId = await _cashOperationsRepositoryClient.RegisterAsync(operation);

            if (operationId != operation.Id)
            {
                _log.Warning($"Unexpected response from Operations Service: {operationId}",
                             context: operation.ToJson());
            }

            ChaosKitty.Meow();
        }
        public async Task <CommandHandlingResult> Handle(RegisterCashInOutCommand command, IEventPublisher eventPublisher)
        {
            var id          = command.CommandId;
            var asset       = command.Asset;
            var amount      = command.Amount;
            var transaction = command.Transaction;

            ChaosKitty.Meow();

            try
            {
                await _cashOperationsRepositoryClient.RegisterAsync(new CashInOutOperation
                {
                    Id             = id,
                    ClientId       = transaction.ClientId,
                    Multisig       = transaction.Multisig,
                    AssetId        = asset.Id,
                    Amount         = amount,
                    BlockChainHash = transaction.Hash,
                    DateTime       = DateTime.UtcNow,
                    AddressTo      = transaction.Multisig,
                    State          = TransactionStates.SettledOnchain
                });
            }
            catch (HttpOperationException)
            {
                var persistedOperation = await _cashOperationsRepositoryClient.GetAsync(transaction.ClientId, id);

                if (persistedOperation == null)
                {
                    throw;
                }
                // else assuming that operation was correctly persisted before
            }

            eventPublisher.PublishEvent(new CashInOutOperationRegisteredEvent
            {
                CommandId   = command.CommandId,
                Asset       = command.Asset,
                Amount      = command.Amount,
                Transaction = command.Transaction
            });

            return(CommandHandlingResult.Ok());
        }