public async Task <object> Withdraw([FromBody] WithdrawRequest request) { try { var platformId = BitcornUtils.GetPlatformId(request.Id); var user = await BitcornUtils.GetUserForPlatform(platformId, _dbContext).FirstOrDefaultAsync(); var response = new Dictionary <string, object>(); if (user != null) { var withdrawResult = await WalletUtils.Withdraw(_dbContext, _configuration, user, request.CornAddy, request.Amount, platformId.Platform); response.Add("usererror", withdrawResult.UserError); response.Add("walletavailable", withdrawResult.WalletAvailable); response.Add("txid", withdrawResult.WalletObject); if (request.Columns.Length > 0) { var columns = await UserReflection.GetColumns(_dbContext, request.Columns, new int[] { user.UserId }); if (columns.Count > 0) { foreach (var item in columns.First().Value) { response.Add(item.Key, item.Value); } } } if (withdrawResult.WalletObject != null && request.Amount > 100000) { await BitcornUtils.TxTracking(_configuration, new { txid = withdrawResult.WalletObject, time = DateTime.Now, method = "withdraw", platform = platformId.Platform, amount = request.Amount, userid = user.UserId, twitchUsername = user.UserIdentity.TwitchUsername, discordUsername = user.UserIdentity.DiscordUsername, cornaddy = request.CornAddy, }); } } return(response); } catch (Exception e) { await BITCORNLogger.LogError(_dbContext, e); throw e; } }
public async Task <ActionResult <object> > Withdraw([FromBody] WithdrawRequest request) { try { var platformId = BitcornUtils.GetPlatformId(request.Id); var user = this.GetCachedUser();//await BitcornUtils.GetUserForPlatform(platformId, _dbContext).FirstOrDefaultAsync(); var response = new Dictionary <string, object>(); if (user != null) { if (user.UserWallet.IsLocked != null && user.UserWallet.IsLocked.Value) { return(StatusCode(420)); } //if (user.MFA) { if (user.UserWallet.Balance < 30_000_000) { var withdrawResult = await WalletUtils.Withdraw(_dbContext, _configuration, user, request.CornAddy, request.Amount, platformId.Platform); response.Add("usererror", withdrawResult.UserError); response.Add("walletavailable", withdrawResult.WalletAvailable); response.Add("txid", withdrawResult.WalletObject); if (withdrawResult.ErrorCode != null && withdrawResult.ErrorCode == Utils.Wallet.Models.WalletErrorCodes.RPC_WALLET_INSUFFICIENT_FUNDS) { await BitcornUtils.TxTracking(_configuration, new { message = "Insufficient funds detected on wallet on withdraw, (this might be because of no mature utxos) address to deposit from cold reserve = " + withdrawResult.DepositAddress }); } await FillColumns(response, request, user); if (withdrawResult.WalletObject != null && request.Amount > 100000) { await BitcornUtils.TxTracking(_configuration, new { txid = withdrawResult.WalletObject, time = DateTime.Now, method = "withdraw", platform = platformId.Platform, amount = request.Amount, userid = user.UserId, twitchUsername = user.UserIdentity.TwitchUsername, discordUsername = user.UserIdentity.DiscordUsername, cornaddy = request.CornAddy, }); } } else { response.Add("usererror", false); response.Add("walletavailable", false); response.Add("txid", null); await FillColumns(response, request, user); await BitcornUtils.TxTracking(_configuration, new { message = "Withdraw cancelled, manual withdraw required.", time = DateTime.Now, platform = platformId.Platform, amount = request.Amount, userid = user.UserId, twitchUsername = user.UserIdentity.TwitchUsername, discordUsername = user.UserIdentity.DiscordUsername, cornaddy = request.CornAddy, }); } } /* * else * { * await FillColumns(response, request, user); * response.Add("usererror", false); * response.Add("walletavailable", false); * response.Add("txid", null); * }*/ } return(response); } catch (Exception e) { await BITCORNLogger.LogError(_dbContext, e, JsonConvert.SerializeObject(request)); throw e; } }