Example #1
0
        public async Task <CommandHandlingResult> Handle(ProcessHotWalletErc20EventCommand command, IEventPublisher eventPublisher)
        {
            try
            {
                switch (command.EventType)
                {
                case HotWalletEventType.CashinCompleted:
                    await ProcessHotWalletCashin(command, eventPublisher);

                    break;

                case HotWalletEventType.CashoutCompleted:
                    await ProcessHotWalletCashout(command);

                    break;

                default:
                    throw new ArgumentOutOfRangeException($"{command.EventType} - is not supported for processing {command.ToJson()}. ");
                }

                return(CommandHandlingResult.Ok());
            }
            catch (Exception e)
            {
                _log.Error(nameof(ProcessHotWalletErc20EventCommand), e, context: command);
                throw;
            }
        }
Example #2
0
        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 <CommandHandlingResult> Handle(ProcessHotWalletErc20EventCommand command, IEventPublisher eventPublisher)
        {
            var sw = new Stopwatch();

            sw.Start();

            try
            {
                switch (command.EventType)
                {
                case HotWalletEventType.CashinCompleted:
                    await ProcessHotWalletCashin(command, eventPublisher);

                    break;

                case HotWalletEventType.CashoutCompleted:
                    await ProcessHotWalletCashout(command);

                    break;

                default:
                    throw new ArgumentOutOfRangeException(
                              $"{command.EventType} - is not supported for processing {command.ToJson()}. ");
                }

                return(CommandHandlingResult.Ok());
            }
            catch (Exception e)
            {
                _log.Error(nameof(ProcessHotWalletErc20EventCommand), e, context: command);
                throw;
            }
            finally
            {
                sw.Stop();
                _log.Info("Command execution time",
                          context: new { TxHandler = new { Handler = nameof(EthereumCoreCommandHandler), Command = nameof(ProcessHotWalletErc20EventCommand),
                                                           Time    = sw.ElapsedMilliseconds } });
            }
        }
Example #4
0
        private async Task ProcessHotWalletCashin(ProcessHotWalletErc20EventCommand queueMessage,
                                                  IEventPublisher eventPublisher)
        {
            var bcnCreds = await _bcnClientCredentialsRepository.GetByAssetAddressAsync(queueMessage.FromAddress);

            string tokenAddress = queueMessage.TokenAddress;
            var    token        = await _assetsService.Erc20TokenGetByAddressAsync(tokenAddress);

            if (token == null)
            {
                _log.Error(new Exception($"Skipping cashin. Unsupported Erc 20 token - {tokenAddress}"),
                           context: queueMessage);

                return;
            }
            var asset = await _assetsServiceWithCache.TryGetAssetAsync(token.AssetId);

            var amount = EthServiceHelpers.ConvertFromContract(queueMessage.Amount, asset.MultiplierPower, asset.Accuracy);

            Guid.TryParse(bcnCreds.ClientId, out var clientId);

            await HandleCashInOperation(asset, amount, clientId,
                                        bcnCreds.Address, queueMessage.TransactionHash, eventPublisher);
        }