Ejemplo n.º 1
0
        public async Task <ActionResult <FullUser> > CreateCornaddy([FromBody] CreateCornaddyRequest request)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(request.Id))
                {
                    throw new ArgumentNullException("id");
                }

                var platformId = BitcornUtils.GetPlatformId(request.Id);

                var user = await BitcornUtils.GetUserForPlatform(platformId, _dbContext).FirstOrDefaultAsync();

                if (user != null)
                {
                    var walletResponse = await WalletUtils.CreateCornaddy(_dbContext, user.UserWallet, _configuration);

                    if (!walletResponse.WalletAvailable)
                    {
                        return(StatusCode((int)HttpStatusCode.ServiceUnavailable));
                    }
                    return(BitcornUtils.GetFullUser(user, user.UserIdentity, user.UserWallet, user.UserStat));
                }
                else
                {
                    return(StatusCode(500));
                }
            }
            catch (Exception e)
            {
                await BITCORNLogger.LogError(_dbContext, e);

                throw e;
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <SubscriptionResponse> > New([FromBody] SubRequest subRequest)
        {
            var platformId = BitcornUtils.GetPlatformId(subRequest.Id);
            var user       = await BitcornUtils.GetUserForPlatform(platformId, _dbContext).FirstOrDefaultAsync();

            if (user != null && UserLockCollection.Lock(user.UserId))
            {
                try
                {
                    subRequest.Platform = platformId.Platform;
                    var tx = await SubscriptionUtils.Subscribe(_dbContext, user, subRequest);

                    if (tx != null)
                    {
                        return(tx);
                    }
                }
                catch (Exception e)
                {
                    await BITCORNLogger.LogError(_dbContext, e, JsonConvert.SerializeObject(subRequest));

                    throw e;
                }
                finally
                {
                    UserLockCollection.Release(user.UserId);
                }
            }

            return(StatusCode((int)HttpStatusCode.BadRequest));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <object> > GetUserSubscriptions([FromRoute] string platformId, [FromRoute] string subscriptionName = null)
        {
            if (string.IsNullOrEmpty(platformId))
            {
                throw new ArgumentException("platformId");
            }

            try
            {
                var id   = BitcornUtils.GetPlatformId(platformId);
                var user = await BitcornUtils.GetUserForPlatform(id, _dbContext).FirstOrDefaultAsync();

                if (user != null)
                {
                    var now = DateTime.Now;
                    var subscriptionsQuery = SubscriptionUtils.GetUserSubscriptions(_dbContext, user)
                                             .Join(_dbContext.Subscription,
                                                   (UserSubcriptionTierInfo info) => info.SubscriptionTier.SubscriptionId,
                                                   (Subscription sub) => sub.SubscriptionId,
                                                   (info, sub) => new
                    {
                        userInfo         = info,
                        subscriptionInfo = sub
                    }).Where(s => s.userInfo.UserSubscription.LastSubDate.Value.AddDays(s.subscriptionInfo.Duration) > now);

                    if (string.IsNullOrEmpty(subscriptionName) || subscriptionName == "*")
                    {
                        return(await subscriptionsQuery.Select(s => new
                        {
                            daysLeft = (s.userInfo.UserSubscription.LastSubDate.Value.AddDays(s.subscriptionInfo.Duration) - now).TotalDays,
                            tier = s.userInfo.SubscriptionTier.Tier,
                            name = s.subscriptionInfo.Name,
                            description = s.subscriptionInfo.Description,
                            lastSubDate = s.userInfo.UserSubscription.LastSubDate
                        }).ToArrayAsync());
                    }
                    else
                    {
                        return(await subscriptionsQuery.Where(q => q.subscriptionInfo.Name.ToLower() == subscriptionName.ToLower()).Select(s => new
                        {
                            daysLeft = (s.userInfo.UserSubscription.LastSubDate.Value.AddDays(s.subscriptionInfo.Duration) - now).TotalDays,
                            tier = s.userInfo.SubscriptionTier.Tier,
                            name = s.subscriptionInfo.Name,
                            description = s.subscriptionInfo.Description,
                            lastSubDate = s.userInfo.UserSubscription.LastSubDate
                        }).ToArrayAsync());
                    }
                }
                else
                {
                    return(StatusCode(404));
                }
            }
            catch (Exception e)
            {
                await BITCORNLogger.LogError(_dbContext, e, JsonConvert.SerializeObject(new { platformId, subscriptionName }));

                throw e;
            }
        }
Ejemplo n.º 4
0
        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 <HttpStatusCode> Post([FromBody] ReferralUpload referralUpload)
        {
            var platformId = BitcornUtils.GetPlatformId(referralUpload.UserId);
            var user       = await BitcornUtils.GetUserForPlatform(platformId, _dbContext).FirstOrDefaultAsync();

            if (user != null)
            {
                if (!_dbContext.Referrer.Any(r => r.UserId == user.UserId))
                {
                    try
                    {
                        if (referralUpload == null)
                        {
                            throw new ArgumentNullException(nameof(referralUpload));
                        }

                        var referrer = new Referrer();
                        referrer.Amount   = 10;
                        referrer.UserId   = user.UserId;
                        referrer.Tier     = 0;
                        referrer.YtdTotal = 0;
                        referrer.ETag     = referralUpload.W9.ETag;
                        referrer.Key      = referralUpload.W9.Key;
                        _dbContext.Referrer.Add(referrer);
                        await _dbContext.SaveAsync();

                        return(HttpStatusCode.OK);
                    }
                    catch (Exception e)
                    {
                        await BITCORNLogger.LogError(_dbContext, e, JsonConvert.SerializeObject(referralUpload));

                        throw;
                    }
                }

                var referrer1 = await _dbContext.Referrer.FirstOrDefaultAsync(r => r.UserId == user.UserId);

                referrer1.ETag = referralUpload.W9.ETag;
                referrer1.Key  = referralUpload.W9.Key;
                await _dbContext.SaveAsync();

                return(HttpStatusCode.OK);
            }
            return(HttpStatusCode.BadRequest);
        }
Ejemplo n.º 6
0
        public async Task <ActionResult <bool> > IsSubbed([FromRoute] string platformId, [FromRoute] string subscriptionName, [FromQuery] string subTier = null)
        {
            if (string.IsNullOrEmpty(platformId))
            {
                throw new ArgumentException("platformId");
            }
            if (string.IsNullOrEmpty(subscriptionName))
            {
                throw new ArgumentException("subscriptionName");
            }
            try
            {
                var id   = BitcornUtils.GetPlatformId(platformId);
                var user = await BitcornUtils.GetUserForPlatform(id, _dbContext).FirstOrDefaultAsync();

                if (user != null)
                {
                    int?tier = null;
                    if (!string.IsNullOrEmpty(subTier))
                    {
                        try
                        {
                            tier = int.Parse(subTier);
                        }
                        catch { }
                    }

                    return(await SubscriptionUtils.HasSubscribed(_dbContext, user, subscriptionName, tier));
                }
                else
                {
                    return(StatusCode(404));
                }
            }
            catch (Exception e)
            {
                await BITCORNLogger.LogError(_dbContext, e, JsonConvert.SerializeObject(new {
                    subTier,
                    platformId,
                    subscriptionName
                }));

                throw e;
            }
        }
Ejemplo n.º 7
0
        public async Task <ActionResult <object> > Ban([FromBody] BanUserRequest request)
        {
            if (string.IsNullOrWhiteSpace(request.Sender))
            {
                throw new ArgumentNullException("Sender");
            }

            if (string.IsNullOrWhiteSpace(request.BanUser))
            {
                throw new ArgumentNullException("BanUser");
            }

            var senderPlatformId = BitcornUtils.GetPlatformId(request.Sender);
            var senderUser       = await BitcornUtils.GetUserForPlatform(senderPlatformId, _dbContext).FirstOrDefaultAsync();

            if (senderUser != null && senderUser.Level == "5000")
            {
                var banPlatformId = BitcornUtils.GetPlatformId(request.BanUser);
                var primaryKey    = -1;

                var banUser = await BitcornUtils.GetUserForPlatform(banPlatformId, _dbContext).FirstOrDefaultAsync();

                if (banUser != null)
                {
                    primaryKey       = banUser.UserId;
                    banUser.IsBanned = true;
                    _dbContext.Update(banUser);

                    await _dbContext.SaveAsync();
                }
                var users = await UserReflection.GetColumns(_dbContext, new string[] { "*" }, new[] { primaryKey });

                if (users.Count > 0)
                {
                    return(users.First());
                }
                return(null);
            }
            else
            {
                return(StatusCode((int)HttpStatusCode.Forbidden));
            }
        }
Ejemplo n.º 8
0
        public async Task <ActionResult <FullUser> > Post([FromRoute] string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentNullException("id");
            }

            var platformId = BitcornUtils.GetPlatformId(id);
            var user       = await BitcornUtils.GetUserForPlatform(platformId, _dbContext).FirstOrDefaultAsync();

            if (user != null)
            {
                return(BitcornUtils.GetFullUser(user, user.UserIdentity, user.UserWallet, user.UserStat));
            }
            else
            {
                return(StatusCode(404));
            }
        }
Ejemplo n.º 9
0
        public async Task <ActionResult <FullUser> > CreateCornaddy([FromBody] CreateCornaddyRequest request)
        {
            try
            {
                if (this.GetCachedUser() != null)
                {
                    throw new InvalidOperationException();
                }
                if (string.IsNullOrWhiteSpace(request.Id))
                {
                    throw new ArgumentNullException("id");
                }

                var platformId = BitcornUtils.GetPlatformId(request.Id);

                var user = await BitcornUtils.GetUserForPlatform(platformId, _dbContext).FirstOrDefaultAsync();

                if (user != null)
                {
                    var walletResponse = await WalletUtils.CreateCornaddy(_dbContext, user.UserWallet, _configuration);

                    if (!walletResponse.WalletAvailable)
                    {
                        user.UserWallet.CornAddy = "<no enabled wallets found>";
                        await _dbContext.SaveAsync();

                        return(StatusCode(200));
                        //return StatusCode((int)HttpStatusCode.ServiceUnavailable);
                    }
                    return(BitcornUtils.GetFullUser(user, user.UserIdentity, user.UserWallet, user.UserStat));
                }
                else
                {
                    return(StatusCode(500));
                }
            }
            catch (Exception e)
            {
                await BITCORNLogger.LogError(_dbContext, e, JsonConvert.SerializeObject(request));

                throw e;
            }
        }
Ejemplo n.º 10
0
        public async Task <ActionResult <object> > Get([FromRoute] string platform, [FromRoute] string id)
        {
            try
            {
                var platformId = BitcornUtils.GetPlatformId(id);
                //join wallet in dbContext.UserWallet on identity.UserId equals wallet.UserId

                /*var userQuery = BitcornUtils.GetUserForPlatform(platformId, _dbContext).Join(_dbContext.UserAvatar,
                 *  (User user) => user.UserId,
                 *  (UserAvatar avatar) => avatar.UserId, (us, av) => new
                 *  {
                 *      avatar = av,
                 *      user = us
                 *  });
                 * var userData = await userQuery.FirstOrDefaultAsync();*/
                var user = await BitcornUtils.GetUserForPlatform(platformId, _dbContext)
                           .FirstOrDefaultAsync();

                if (user != null)
                {
                    return(await GameUtils.GetAvatar(_dbContext, user, platform));
                }
                throw new NotImplementedException();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }

            /*
             *
             * User user = null;
             * if ((user = this.GetCachedUser()) == null)
             *  return StatusCode(404);*/
            //return BitcornUtils.GetFullUser(user, user.UserIdentity, user.UserWallet, user.UserStat);
        }
        public async Task <UserIdentity> Auth0([FromRoute] string id)
        {
            var platformId = BitcornUtils.GetPlatformId(id);

            return(await BitcornUtils.GetUserForPlatform(platformId, _dbContext).Select(u => u.UserIdentity).FirstOrDefaultAsync());
        }
Ejemplo n.º 12
0
        public static async Task <int> TryClaimTx(PlatformId platformId, User user, BitcornContext dbContext)
        {
            if (user == null)
            {
                user = await BitcornUtils.GetUserForPlatform(platformId, dbContext).FirstOrDefaultAsync();
            }
            if (user == null)
            {
                return(0);
            }

            bool lockApplied = false;

            try
            {
                if (UserLockCollection.Lock(user))
                {
                    lockApplied = true;
                }
                else
                {
                    return(0);
                }

                var now = DateTime.Now;
                var txs = await dbContext.UnclaimedTx.Where(u => u.Platform == platformId.Platform &&
                                                            u.ReceiverPlatformId == platformId.Id &&
                                                            !u.Claimed && !u.Refunded &&
                                                            u.Expiration > now).ToArrayAsync();

                var sql = new StringBuilder();
                var pk  = nameof(UserWallet.UserId);

                foreach (var tx in txs)
                {
                    tx.Claimed = true;

                    var log = new CornTx();
                    log.Amount     = tx.Amount;
                    log.Platform   = tx.Platform;
                    log.ReceiverId = user.UserId;
                    log.SenderId   = tx.SenderUserId;
                    log.Timestamp  = tx.Timestamp;
                    log.TxGroupId  = Guid.NewGuid().ToString();
                    log.TxType     = tx.TxType;
                    log.UnclaimedTx.Add(tx);
                    dbContext.CornTx.Add(log);

                    sql.Append(TxUtils.ModifyNumber(nameof(UserWallet), nameof(UserWallet.Balance), tx.Amount, '+', pk, user.UserId));
                    sql.Append(TxUtils.ModifyNumber(nameof(UserStat), nameof(UserStat.AmountOfTipsReceived), 1, '+', pk, user.UserId));
                    sql.Append(TxUtils.ModifyNumber(nameof(UserStat), nameof(UserStat.TotalReceivedBitcornTips), tx.Amount, '+', pk, user.UserId));
                    sql.Append(TxUtils.UpdateNumberIfTop(nameof(UserStat), nameof(UserStat.LargestReceivedBitcornTip), tx.Amount, pk, user.UserId));


                    sql.Append(TxUtils.ModifyNumber(nameof(UserStat), nameof(UserStat.AmountOfTipsSent), 1, '+', pk, tx.SenderUserId));
                    sql.Append(TxUtils.ModifyNumber(nameof(UserStat), nameof(UserStat.TotalSentBitcornViaTips), tx.Amount, '+', pk, tx.SenderUserId));
                    sql.Append(TxUtils.UpdateNumberIfTop(nameof(UserStat), nameof(UserStat.LargestSentBitcornTip), tx.Amount, pk, tx.SenderUserId));
                }
                if (txs.Length > 0)
                {
                    await DbOperations.ExecuteSqlRawAsync(dbContext, sql.ToString());

                    await dbContext.SaveAsync();
                }
                return(txs.Length);
            }
            catch (Exception e)
            {
                await BITCORNLogger.LogError(dbContext, e, JsonConvert.SerializeObject(platformId));

                return(0);
            }
            finally
            {
                if (lockApplied)
                {
                    UserLockCollection.Release(user);
                }
            }
        }
Ejemplo n.º 13
0
        public static async Task <int> TryClaimTx(PlatformId platformId, User user, BitcornContext dbContext)
        {
            if (user == null)
            {
                user = await BitcornUtils.GetUserForPlatform(platformId, dbContext).FirstOrDefaultAsync();
            }
            if (user == null)
            {
                return(0);
            }

            bool lockApplied = false;

            try
            {
                lock (LockUserAttribute.LockedUsers)
                {
                    if (LockUserAttribute.LockedUsers.Contains(user.UserId))
                    {
                        return(0);
                    }
                    lockApplied = LockUserAttribute.LockedUsers.Add(user.UserId);
                }

                var now = DateTime.Now;
                var txs = await dbContext.UnclaimedTx.Where(u => u.Platform == platformId.Platform &&
                                                            u.ReceiverPlatformId == platformId.Id &&
                                                            !u.Claimed && !u.Refunded &&
                                                            u.Expiration > now).ToArrayAsync();

                var sql = new StringBuilder();
                var pk  = nameof(UserWallet.UserId);

                foreach (var tx in txs)
                {
                    tx.Claimed = true;

                    var log = new CornTx();
                    log.Amount     = tx.Amount;
                    log.Platform   = tx.Platform;
                    log.ReceiverId = user.UserId;
                    log.SenderId   = tx.SenderUserId;
                    log.Timestamp  = tx.Timestamp;
                    log.TxGroupId  = Guid.NewGuid().ToString();
                    log.TxType     = tx.TxType;
                    log.UnclaimedTx.Add(tx);
                    dbContext.CornTx.Add(log);

                    sql.Append(TxUtils.ModifyNumber(nameof(UserWallet), nameof(UserWallet.Balance), tx.Amount, '+', pk, user.UserId));
                    sql.Append(TxUtils.ModifyNumber(nameof(UserStat), nameof(UserStat.Tipped), 1, '+', pk, user.UserId));
                    sql.Append(TxUtils.ModifyNumber(nameof(UserStat), nameof(UserStat.TippedTotal), tx.Amount, '+', pk, user.UserId));
                    sql.Append(TxUtils.UpdateNumberIfTop(nameof(UserStat), nameof(UserStat.TopTipped), tx.Amount, pk, user.UserId));


                    sql.Append(TxUtils.ModifyNumber(nameof(UserStat), nameof(UserStat.Tip), 1, '+', pk, tx.SenderUserId));
                    sql.Append(TxUtils.ModifyNumber(nameof(UserStat), nameof(UserStat.TipTotal), tx.Amount, '+', pk, tx.SenderUserId));
                    sql.Append(TxUtils.UpdateNumberIfTop(nameof(UserStat), nameof(UserStat.TopTip), tx.Amount, pk, tx.SenderUserId));
                }
                if (txs.Length > 0)
                {
                    await dbContext.Database.ExecuteSqlRawAsync(sql.ToString());

                    await dbContext.SaveAsync();
                }
                return(txs.Length);
            }
            catch (Exception e)
            {
                await BITCORNLogger.LogError(dbContext, e);

                return(0);
            }
            finally
            {
                if (lockApplied)
                {
                    lock (LockUserAttribute.LockedUsers)
                    {
                        LockUserAttribute.LockedUsers.Remove(user.UserId);
                    }
                }
            }
        }
Ejemplo n.º 14
0
        public static async Task <TxProcessInfo> ProcessRequest(ITxRequest req, BitcornContext dbContext)
        {
            if (req.Amount <= 0)
            {
                throw new ArgumentException("Amount");
            }

            var info        = new TxProcessInfo();
            var platformIds = new HashSet <PlatformId>();

            var fromPlatformId = BitcornUtils.GetPlatformId(req.From);

            var fromUser = await BitcornUtils.GetUserForPlatform(fromPlatformId, dbContext).AsNoTracking().FirstOrDefaultAsync();

            info.From = fromUser;

            var toArray = req.To.ToArray();

            var  totalAmountRequired = toArray.Length * req.Amount;
            bool canExecuteAll       = false;

            if (fromUser != null && fromUser.UserWallet.Balance >= totalAmountRequired)
            {
                canExecuteAll = true;
            }

            foreach (var to in toArray)
            {
                var toPlatformId = BitcornUtils.GetPlatformId(to);
                if (!platformIds.Contains(toPlatformId))
                {
                    platformIds.Add(toPlatformId);
                }
            }
            var platformIdArray = platformIds.ToArray();
            var userQuery       = BitcornUtils.GetUsersForPlatform(platformIdArray, dbContext).AsNoTracking();
            var users           = await BitcornUtils.ToPlatformDictionary(platformIdArray, userQuery, dbContext);

            var output = new List <TxReceipt>();
            var txid   = Guid.NewGuid().ToString();
            var sql    = new StringBuilder();

            foreach (var to in platformIdArray)
            {
                var receipt = new TxReceipt();
                if (fromUser != null)
                {
                    receipt.From = new SelectableUser(fromUser);
                }

                if (users.TryGetValue(to.Id, out User user))
                {
                    receipt.To = new SelectableUser(user);
                    if (canExecuteAll)
                    {
                        receipt.Tx = VerifyTx(fromUser, user, req.Amount, req.Platform, req.TxType, txid);
                    }
                    if (receipt.Tx != null)
                    {
                        dbContext.CornTx.Add(receipt.Tx);
                    }
                }
                output.Add(receipt);
            }

            info.Transactions = output.ToArray();
            return(info);
        }
        public async Task <UserWallet> Wallet([FromRoute] string id)
        {
            var platformId = BitcornUtils.GetPlatformId(id);
            var user       = await BitcornUtils.GetUserForPlatform(platformId, _dbContext).FirstOrDefaultAsync();

            if (user != null)
            {
                var userWallet = user.UserWallet;
                if (!UserLockCollection.Lock(userWallet.UserId))
                {
                    return(userWallet);
                }
                try
                {
                    var referralId = _dbContext.UserReferral.FirstOrDefault(r => r.UserId == userWallet.UserId)?.ReferralId;
                    if (referralId != 0 && referralId != null)
                    {
                        var userReferral = await _dbContext.UserReferral.FirstOrDefaultAsync(r => r.UserId == userWallet.UserId);

                        var referrer = await _dbContext.Referrer.FirstOrDefaultAsync(r => r.ReferralId == userReferral.ReferralId);

                        var referrerUser = await _dbContext.JoinUserModels().FirstOrDefaultAsync(w => w.UserId == referrer.UserId);

                        var referrerStat = await _dbContext.UserStat.FirstOrDefaultAsync(s => s.UserId == referrer.UserId);

                        await ReferralUtils.BonusPayout(_dbContext, userReferral, referrer, user, referrerUser, referrerStat);

                        if (referrer != null &&
                            userReferral != null &&
                            userReferral.MinimumBalanceDate == null &&
                            userWallet.Balance >= MIN_BALANCE_QUEST_AMOUNT)
                        {
                            if (referrer.YtdTotal < 600 || (referrer.ETag != null && referrer.Key != null))
                            {
                                var referralPayoutTotal = await ReferralUtils.TotalReward(_dbContext, referrer);

                                var miniumBalanceRewardUser = await TxUtils.SendFromBitcornhub(user, referrer.Amount, "BITCORNFarms", "Minium balance reward", _dbContext);

                                var miniumBalanceReward = await TxUtils.SendFromBitcornhub(referrerUser, referralPayoutTotal, "BITCORNFarms", "Minium balance reward", _dbContext);

                                if (miniumBalanceReward && miniumBalanceRewardUser)
                                {
                                    referrerStat.TotalReferralRewardsCorn += referralPayoutTotal;
                                    referrerStat.TotalReferralRewardsUsdt += (referralPayoutTotal * (await ProbitApi.GetCornPriceAsync(_dbContext)));
                                    userReferral.MinimumBalanceDate        = DateTime.Now;
                                    await ReferralUtils.UpdateYtdTotal(_dbContext, referrer, referralPayoutTotal);

                                    await ReferralUtils.LogReferralTx(_dbContext, user.UserId, referrer.Amount, "Recruit minimum balance Reward");

                                    await ReferralUtils.LogReferralTx(_dbContext, referrerUser.UserId, referralPayoutTotal, "Minimum balance Reward");

                                    await ReferralUtils.BonusPayout(_dbContext, userReferral, referrer, user, referrerUser, referrerStat);
                                }
                            }
                        }
                        await _dbContext.SaveAsync();
                    }
                }
                catch (Exception e)
                {
                    await BITCORNLogger.LogError(_dbContext, e, id);
                }
                finally
                {
                    UserLockCollection.Release(userWallet.UserId);
                }
                return(user.UserWallet);
            }
            else
            {
                return(null);
            }
        }