public async Task ProcessTransferFromLinkedToInternalEvent(LinkedWalletTransferDto transfer)
        {
            var isValid = ValidateTransferFromLinkedToInternalWallet(transfer);

            if (!isValid)
            {
                return;
            }

            AddAdditionalDataToPublicWalletTransfer(transfer, LinkedWalletTransferDirection.Incoming);

            await _linkedWalletTransfersRepository.AddAsync(transfer);
        }
 public static TransactionHistoryEntity CreateForLinkedWalletTransfer(LinkedWalletTransferDto transfer)
 {
     return(new TransactionHistoryEntity
     {
         CustomerId = transfer.CustomerId,
         Timestamp = transfer.Timestamp,
         Type = transfer.Direction == LinkedWalletTransferDirection.Incoming
             ? OperationType.LinkedWalletIncomingTransfer.ToString()
             : OperationType.LinkedWalletOutgoingTransfer.ToString(),
         AssetSymbol = transfer.AssetSymbol,
         TransactionId = transfer.OperationId
     });
 }
Пример #3
0
 public static LinkedWalletTransferEntity Create(LinkedWalletTransferDto transfer)
 {
     return(new LinkedWalletTransferEntity
     {
         Id = transfer.OperationId,
         Amount = transfer.Amount,
         Direction = transfer.Direction,
         CustomerId = transfer.CustomerId,
         PrivateAddress = transfer.PrivateAddress,
         PublicAddress = transfer.PublicAddress,
         Timestamp = transfer.Timestamp,
         AssetSymbol = transfer.AssetSymbol
     });
 }
        public async Task AddAsync(LinkedWalletTransferDto transfer)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var entity = LinkedWalletTransferEntity.Create(transfer);

                var historyEntity = TransactionHistoryEntity.CreateForLinkedWalletTransfer(transfer);

                context.LinkedWalletTransfers.Add(entity);

                context.TransactionHistories.Add(historyEntity);

                await context.SaveChangesAsync();
            }
        }
        private bool ValidateTransferFromLinkedToInternalWallet(LinkedWalletTransferDto transfer)
        {
            bool isValid = true;

            if (transfer.Amount <= 0)
            {
                isValid = false;
                _log.Warning("Processed transfer from linked to internal with invalid amount", context: transfer);
            }

            if (string.IsNullOrEmpty(transfer.CustomerId))
            {
                isValid = false;
                _log.Warning("Transfer from linked to internal without customer id", context: transfer);
            }

            if (string.IsNullOrEmpty(transfer.PrivateAddress))
            {
                isValid = false;
                _log.Warning("Transfer from linked to internal without private address", context: transfer);
            }

            if (string.IsNullOrEmpty(transfer.PublicAddress))
            {
                isValid = false;
                _log.Warning("Transfer from linked to internal without public address", context: transfer);
            }

            if (string.IsNullOrEmpty(transfer.OperationId))
            {
                isValid = false;
                _log.Warning("Transfer from linked to internal without operationId", context: transfer);
            }

            return(isValid);
        }
 private void AddAdditionalDataToPublicWalletTransfer(LinkedWalletTransferDto transfer, LinkedWalletTransferDirection direction)
 {
     transfer.AssetSymbol = _tokenSymbol;
     transfer.Direction   = direction;
     transfer.Timestamp   = DateTime.UtcNow;
 }