Beispiel #1
0
 private async Task UpdateUserTransferWallet(TransferContractTransaction contractTransferTr)
 {
     await _userTransferWalletRepository.ReplaceAsync(new UserTransferWallet()
     {
         LastBalance             = "",
         TransferContractAddress = contractTransferTr.ContractAddress,
         UpdateDate  = DateTime.UtcNow,
         UserAddress = contractTransferTr.UserAddress
     });
 }
Beispiel #2
0
        public async Task TransferToCoinContract(TransferContractTransaction contractTransferTr)
        {
            try
            {
                var contractEntity = await _transferContractRepository.GetAsync(contractTransferTr.ContractAddress);

                var balance = await _transferContractService.GetBalance(contractTransferTr.ContractAddress);

                if (balance == 0)
                {
                    await UpdateUserTransferWallet(contractTransferTr);

                    await _logger.WriteInfoAsync("TransferContractTransactionService", "TransferToCoinContract", "",
                                                 $"Can't cashin: there is no funds on the transfer contract {contractTransferTr.ContractAddress}", DateTime.UtcNow);

                    return;
                }

                var userAddress = await _transferContractService.GetUserAddressForTransferContract(contractTransferTr.ContractAddress);

                if (string.IsNullOrEmpty(userAddress) || userAddress == Constants.EmptyEthereumAddress)
                {
                    await UpdateUserTransferWallet(contractTransferTr);

                    await _logger.WriteInfoAsync("TransferContractTransactionService", "TransferToCoinContract", "",
                                                 $"Can't cashin: there is no user assigned to the transfer contract {contractTransferTr.ContractAddress}", DateTime.UtcNow);

                    return;
                }

                var opId            = $"InternalOperation-{Guid.NewGuid().ToString()}";
                var transactionHash = await _transferContractService.RecievePaymentFromTransferContract(contractEntity.ContractAddress, contractEntity.CoinAdapterAddress);

                await _coinEventService.PublishEvent(new CoinEvent(opId,
                                                                   transactionHash, contractTransferTr.ContractAddress, contractTransferTr.UserAddress,
                                                                   balance.ToString(), CoinEventType.CashinStarted, contractEntity.CoinAdapterAddress));

                await _eventTraceRepository.InsertAsync(new EventTrace()
                {
                    Note        = $"First Cashin appearance {transactionHash} put in {Constants.TransactionMonitoringQueue}",
                    OperationId = opId,
                    TraceDate   = DateTime.UtcNow
                });

                await _userPaymentHistoryRepository.SaveAsync(new UserPaymentHistory()
                {
                    Amount          = balance.ToString(),
                    ToAddress       = contractEntity.ContractAddress,
                    AdapterAddress  = contractEntity.CoinAdapterAddress,
                    CreatedDate     = DateTime.UtcNow,
                    Note            = $"Cashin from transfer contract {contractEntity.ContractAddress}",
                    TransactionHash = transactionHash,
                    UserAddress     = contractTransferTr.UserAddress
                });

                //await UpdateUserTransferWallet(contractTransferTr);
                await _logger.WriteInfoAsync("ContractTransferTransactionService", "TransferToCoinContract", "",
                                             $"Transfered {balance} from transfer contract to \"{contractTransferTr.CoinAdapterAddress}\" by transaction \"{transactionHash}\". Receiver = {contractEntity.UserAddress}");
            }
            catch (Exception e)
            {
                await _logger.WriteErrorAsync("TransferContractTransactionService", "TransferToCoinContract",
                                              $"{contractTransferTr.ContractAddress} - {contractTransferTr.CoinAdapterAddress} - {contractTransferTr.Amount}", e);

                throw;
            }
        }
Beispiel #3
0
 public async Task PutContractTransferTransaction(TransferContractTransaction tr)
 {
     await _queue.PutRawMessageAsync(JsonConvert.SerializeObject(tr));
 }