public async Task <IActionResult> GetDepositContract([FromQuery] string userAddress) { var contractAddress = await _contractService.GetContractAddress(userAddress); return(Ok(new RegisterResponse { Contract = contractAddress })); }
public async Task <IActionResult> GetDepositContractAsync([FromQuery][Required] string userAddress) { if (!ModelState.IsValid) { throw new ClientSideException(ExceptionType.WrongParams, JsonConvert.SerializeObject(ModelState.Errors())); } var contractAddress = await _contractService.GetContractAddress(userAddress); return(Ok(new RegisterResponse { Contract = contractAddress })); }
public async Task TransferToCoinContract(Erc20DepositContractTransaction contractTransferTr) { try { var userAddress = contractTransferTr.UserAddress; 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 tokenAddress = contractTransferTr.TokenAddress; var contractAddress = await _erc20DepositContractService.GetContractAddress(contractTransferTr.UserAddress); var balance = await _ercInterfaceService.GetBalanceForExternalTokenAsync(contractTransferTr.ContractAddress, contractTransferTr.TokenAddress); 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 opId = $"HotWalletCashin-{Guid.NewGuid().ToString()}"; string transactionHash = null; try { transactionHash = await _hotWalletService.StartCashinAsync(new HotWalletOperation() { Amount = balance, FromAddress = contractAddress, OperationId = opId, ToAddress = _hotWalletAddress, TokenAddress = tokenAddress, OperationType = HotWalletOperationType.Cashin, }); } catch (Exception exc) { await UpdateUserTransferWallet(contractTransferTr); return; } await _userPaymentHistoryRepository.SaveAsync(new UserPaymentHistory() { Amount = balance.ToString(), ToAddress = contractAddress, AdapterAddress = $"HotWallet-Token-{tokenAddress}", CreatedDate = DateTime.UtcNow, Note = $"Cashin from erc20 deposit contract {contractAddress}", TransactionHash = transactionHash, UserAddress = contractTransferTr.UserAddress }); //await UpdateUserTransferWallet(contractTransferTr); await _logger.WriteInfoAsync(nameof(Erc20DepositTransactionService), nameof(TransferToCoinContract), "", $"Transfered {balance} from erc 20 deposit contract to {_hotWalletAddress} by transaction {transactionHash}. " + $"Receiver = {userAddress}"); } catch (Exception e) { await _logger.WriteErrorAsync(nameof(Erc20DepositTransactionService), nameof(TransferToCoinContract), $"{contractTransferTr.ContractAddress} - erc20 - {contractTransferTr.TokenAddress} - {contractTransferTr.Amount}", e); throw; } }