static async Task <bool> ShareSubscriptionPaymentWithReferrer(BitcornContext dbContext, Subscription subInfo, decimal cost, SubTx subTx, Referrer referrer, User referrerUser, User subscriptionPaymentRecipient) { if (referrer.EnableSubscriptionRewards) { //get referrer user info if (!subInfo.RestrictReferralRewards || (subInfo.RestrictReferralRewards && (referrerUser.Level == "BEST" || referrerUser.Level == "BAIT" || referrerUser.IsAdmin() || referrer.Tier >= 3))) { //calculate amount that will be sent to the referrer var referralShare = cost * subInfo.ReferrerPercentage.Value; //prepare transaction to the referrer var referralShareTx = await TxUtils.PrepareTransaction(subscriptionPaymentRecipient, referrerUser, referralShare, "BITCORNFarms", "$sub referral share", dbContext); //make sure stat tracking values have been initialized if (referrerUser.UserStat.TotalReferralRewardsCorn == null) { referrerUser.UserStat.TotalReferralRewardsCorn = 0; } //make sure stat tracking values have been initialized if (referrerUser.UserStat.TotalReferralRewardsUsdt == null) { referrerUser.UserStat.TotalReferralRewardsUsdt = 0; } //increment total received corn rewards referrerUser.UserStat.TotalReferralRewardsCorn += referralShare; //inceremnt total received usdt rewards referrerUser.UserStat.TotalReferralRewardsUsdt += ((referralShare) * (await ProbitApi.GetCornPriceAsync(dbContext))); //execute transaction if (await TxUtils.ExecuteTransaction(referralShareTx, dbContext)) { //if transaction was made, log & update ytd total await ReferralUtils.UpdateYtdTotal(dbContext, referrer, referralShare); var referralTx = await ReferralUtils.LogReferralTx(dbContext, referrerUser.UserId, referralShare, "$sub referral share"); subTx.ReferralTxId = referralTx.ReferralTxId; await dbContext.SaveAsync(); return(true); } } } return(false); }