def bch_send_coin_to_holdings(amount, user_id, comment): """ # TO clearnet_webapp # this function will move the coin from vendor to clearnet holdings. This is for vendor verification :param amount: :param user_id: :param comment: :return: """ a = bch_check_balance(user_id=user_id, amount=amount) if a == 1: type_transaction = 7 now = datetime.datetime.utcnow() user = db.session\ .query(Auth_User)\ .filter(Auth_User.id == user_id)\ .first() userswallet = db.session\ .query(Bch_Wallet)\ .filter_by(user_id=user_id)\ .first() curbal = Decimal(userswallet.currentbalance) amounttomod = floating_decimals(amount, 8) newbalance = floating_decimals(curbal, 8) - floating_decimals( amounttomod, 8) userswallet.currentbalance = newbalance db.session.add(userswallet) db.session.flush() c = str(comment) a = Decimal(amount) commentstring = "Vendor Verification: Level " + c bch_add_transaction(category=type_transaction, amount=amount, user_id=user.id, comment=commentstring, shard=user.shard_btccash, orderid=0, balance=newbalance) getcurrentholdings = db.session\ .query(Admin_ClearnetHoldingsBCH)\ .order_by(Admin_ClearnetHoldingsBCH.id.desc())\ .first() currentamount = floating_decimals(getcurrentholdings.total, 8) newamount = floating_decimals(currentamount, 8) + floating_decimals( a, 8) holdingsaccount = Admin_ClearnetHoldingsBCH(amount=a, timestamp=now, user_id=user_id, total=newamount) db.session.add(holdingsaccount)
def getbalanceunconfirmed(user_id): """ this function removes the amount from unconfirmed """ unconfirmeddelete = BtcUnconfirmedTest.query.filter_by( user_id=user_id).first() a = Decimal(unconfirmeddelete.unconfirmed1) b = Decimal(unconfirmeddelete.unconfirmed2) c = Decimal(unconfirmeddelete.unconfirmed3) d = Decimal(unconfirmeddelete.unconfirmed4) e = Decimal(unconfirmeddelete.unconfirmed5) total = a + b + c + d + e wallet = BtcWalletTest.query.filter_by(user_id=user_id).first() totalchopped = floating_decimals(total, 8) wallet.unconfirmed = totalchopped db.session.add(wallet)
def sendcoin(): form = WalletSendcoin() if request.method == "GET": pass if request.method == "POST": wallet = db.session\ .query(BchWallet)\ .filter(BchWallet.user_id == current_user.id)\ .first_or_404() # get walletfee walletthefee = db.session\ .query(BchWalletFee)\ .get(1) wfee = Decimal(walletthefee.bch) if form.validate_on_submit(): if User.decryptpassword(pwdhash=current_user.wallet_pin, password=form.pin.data): sendto = form.sendto.data comment = form.description.data amount = form.amount.data # test wallet_bch stuff for security walbal = Decimal(wallet.currentbalance) amount2withfee = Decimal(amount) + Decimal(wfee) # greater than amount with fee if floating_decimals(walbal, 8) >= floating_decimals( amount2withfee, 8): # greater than fee if Decimal(amount) > Decimal(wfee): # add to wallet_bch work bch_cash_send_coin_offsite(user_id=current_user.id, sendto=sendto, amount=amount, comment=comment) flash("BCH Sent: " + str(sendto), category="success") flash( "Please allow a few minutes for your coin to be added to transactions", category="success") return redirect( url_for('wallet_bch.home', user_name=current_user.user_name)) else: flash("Cannot withdraw amount less than fee: " + str(wfee), category="danger") return redirect( url_for('wallet_bch.home', user_name=current_user.user_name)) else: flash( "Cannot withdraw more than your balance including fee.", category="danger") return redirect( url_for('wallet_bch.home', user_name=current_user.user_name)) else: flash("Invalid Pin.", category="danger") return redirect( url_for('wallet_bch.home', user_name=current_user.user_name)) else: flash("Form Error. Did you enter something inccorrectly? ", category="danger") return redirect( url_for('wallet_bch.home', user_name=current_user.user_name))
def sendcoin(user_id, sendto, amount, comment): """ # This function sends the coin off site """ # variables dcurrency = digital_currency timestamp = datetime.utcnow() # get the fee from db getwallet = db.session.query(Bch_WalletFee).filter_by(id=1).first() walletfee = getwallet.btc # get the users wall userswallet = db.session.query(Bch_Wallet).filter_by( user_id=user_id).first() # proceed to see if balances check curbal = floating_decimals(userswallet.currentbalance, 8) amounttomod = floating_decimals(amount, 8) adjusted_amountadd = floating_decimals(amounttomod - walletfee, 8) adjusted_amount = floating_decimals(adjusted_amountadd, 8) sendto_str = str(sendto) final_amount_str = str(adjusted_amount) comment_str = str(comment) # double check user securetosend = securitybeforesending(sendto=sendto, user_id=user_id, adjusted_amount=adjusted_amount) if securetosend is True: # send call to rpc cmdsendcoin = sendcoincall(address=str(sendto_str), amount=str(final_amount_str), comment=str(comment_str)) print("sending a transaction..") print(user_id) print("txid: ", cmdsendcoin['result']) print("*" * 15) txid = cmdsendcoin['result'] # adds to transactions with txid and confirmed = 0 so we can watch it trans = Bch_WalletTransactions(category=2, user_id=user_id, confirmations=0, txid=txid, blockhash='', timeoft=0, timerecieved=0, otheraccount=0, address='', fee=walletfee, created=timestamp, commentbch=comment_str, amount=amount, orderid=0, balance=curbal, confirmed=0, digital_currency=dcurrency) sendnotification(user_id, notetype=204) db.session.add(userswallet) db.session.add(trans) else: sendnotification(user_id, notetype=200)
def exppoint(user_id, category): from app import db from app.classes.models import ExpTable from app.classes.user import UserStats from datetime import datetime from app.common.functions import floating_decimals # category 1 = User Posted # category 2 = User commented # category 3 = upvoted # category 4 = downvoted # category 5 = sent coin # category 6 = recieved coin # category 7 = created sub # category 8 = gave vote now = datetime.utcnow() points_createdsub = 50 created_post = 10 created_comment = 5 points_upvote = 2 points_downvote = -5 points_sentcoin = 100 points_recievedcoin = 10 gave_vote = 1 # get current user stats getuser = db.session.query(UserStats) getuser = getuser.filter(UserStats.user_id == user_id) guser = getuser.first() # current user points currentpoints = guser.user_exp if 0 <= guser.user_level <= 2: experienceperlevel = 250 elif 3 <= guser.user_level <= 5: experienceperlevel = 500 elif 6 <= guser.user_level <= 7: experienceperlevel = 1000 elif 8 <= guser.user_level <= 10: experienceperlevel = 2000 elif 11 <= guser.user_level <= 14: experienceperlevel = 4000 elif 16 <= guser.user_level <= 20: experienceperlevel = 6000 elif 21 <= guser.user_level <= 25: experienceperlevel = 10000 elif 26 <= guser.user_level <= 30: experienceperlevel = 10000 elif 26 <= guser.user_level <= 30: experienceperlevel = 10000 elif 26 <= guser.user_level <= 30: experienceperlevel = 10000 elif 30 <= guser.user_level <= 50: experienceperlevel = 10000 elif 51 <= guser.user_level <= 100: experienceperlevel = 10000 elif 101 <= guser.user_level <= 151: experienceperlevel = 10000 else: experienceperlevel = 10000 # category 1 = User Posted if category == 1: # ads current points to variable points addpoints = int(currentpoints + created_post) # uses exp per level schema levels_up, exp_to_next = divmod(addpoints, experienceperlevel) # add exp table exp = ExpTable( user_id=user_id, type=1, amount=created_post, created=now, ) db.session.add(exp) # category 2 = User commented elif category == 2: # adds current points to variable points addpoints = int(currentpoints + created_comment) # uses exp per level chema levels_up, exp_to_next = divmod(addpoints, experienceperlevel) # add stats to user # add exp table exp = ExpTable( user_id=user_id, type=2, amount=created_comment, created=now, ) db.session.add(exp) # category 3 = got upvoted elif category == 3: # adds current points to variable points addpoints = int(currentpoints + points_upvote) # uses exp per level chema levels_up, exp_to_next = divmod(addpoints, experienceperlevel) # add stats to user # add exp table exp = ExpTable( user_id=user_id, type=3, amount=points_upvote, created=now, ) db.session.add(exp) # category 4 = got downvote elif category == 4: # adds current points to variable points addpoints = int(currentpoints + points_downvote) # uses exp per level chema levels_up, exp_to_next = divmod(addpoints, experienceperlevel) # add stats to user # add exp table exp = ExpTable( user_id=user_id, type=4, amount=points_downvote, created=now, ) db.session.add(exp) # category 5 = sent coin elif category == 5: addpoints = int((currentpoints + points_sentcoin)) levels_up, exp_to_next = divmod(addpoints, experienceperlevel) exp = ExpTable( user_id=user_id, type=5, amount=points_sentcoin, created=now, ) db.session.add(exp) # category 6 = recieved coin elif category == 6: # adds current points to variable points addpoints = int(currentpoints + points_recievedcoin) # uses exp per level chema levels_up, exp_to_next = divmod(addpoints, experienceperlevel) # add stats to user # add exp table exp = ExpTable( user_id=user_id, type=6, amount=points_recievedcoin, created=now, ) db.session.add(exp) # category 7 = created room elif category == 7: # adds current points to variable points addpoints = int(currentpoints + points_createdsub) # uses exp per level chema levels_up, exp_to_next = divmod(addpoints, experienceperlevel) # add stats to user # add exp table exp = ExpTable( user_id=user_id, type=7, amount=points_createdsub, created=now, ) db.session.add(exp) # category 8 = gave vote elif category == 8: # ads current points to variable points addpoints = int(currentpoints + gave_vote) # uses exp per level chema levels_up, exp_to_next = divmod(addpoints, experienceperlevel) # add stats to user # add exp table exp = ExpTable( user_id=user_id, type=8, amount=gave_vote, created=now, ) db.session.add(exp) else: exp_to_next = guser.user_exp levels_up = 0 db.session.flush() # if user leveled up if levels_up > 0: guser.user_level = guser.user_level + levels_up randomcoin(user_id=user_id, newlevel=guser.user_level) # set new width of exp bar if 0 <= guser.user_level <= 2: user1width_calculator = (guser.user_exp / 250) * 100 user1width = floating_decimals(user1width_calculator, 0) elif 3 <= guser.user_level <= 5: user1width_calculator = (guser.user_exp / 500) * 100 user1width = floating_decimals(user1width_calculator, 0) elif 6 <= guser.user_level <= 7: user1width_calculator = (guser.user_exp / 1000) * 100 user1width = floating_decimals(user1width_calculator, 0) elif 8 <= guser.user_level <= 10: user1width_calculator = (guser.user_exp / 2000) * 100 user1width = floating_decimals(user1width_calculator, 0) elif 11 <= guser.user_level <= 14: user1width_calculator = (guser.user_exp / 4000) * 100 user1width = floating_decimals(user1width_calculator, 0) elif 16 <= guser.user_level <= 20: user1width_calculator = (guser.user_exp / 6000) * 100 user1width = floating_decimals(user1width_calculator, 0) elif 21 <= guser.user_level <= 25: user1width_calculator = (guser.user_exp / 10000) * 100 user1width = floating_decimals(user1width_calculator, 0) elif 26 <= guser.user_level <= 30: user1width_calculator = (guser.user_exp / 15500) * 100 user1width = floating_decimals(user1width_calculator, 0) elif 26 <= guser.user_level <= 30: user1width_calculator = (guser.user_exp / 25000) * 100 user1width = floating_decimals(user1width_calculator, 0) elif 26 <= guser.user_level <= 30: user1width_calculator = (guser.user_exp / 50000) * 100 user1width = floating_decimals(user1width_calculator, 0) elif 30 <= guser.user_level <= 50: user1width_calculator = (guser.user_exp / 50000) * 100 user1width = floating_decimals(user1width_calculator, 0) elif 51 <= guser.user_level <= 100: user1width_calculator = (guser.user_exp / 100000) * 100 user1width = floating_decimals(user1width_calculator, 0) else: user1width_calculator = (guser.user_exp / 100000) * 100 user1width = floating_decimals(user1width_calculator, 0) guser.user_exp = exp_to_next guser.user_width_next_level = str(user1width) db.session.add(guser) db.session.flush()
def userwidthtonextlevel(user_id): from app.classes.user import UserStats from app import db from app.common.functions import floating_decimals userstatspoints = db.session\ .query(UserStats)\ .filter_by(user_id=user_id)\ .first() if 0 <= userstatspoints.user_level <= 3: user1widthh = (userstatspoints.user_exp / 300) * 100 user1width = floating_decimals(user1widthh, 0) elif 4 <= userstatspoints.user_level <= 7: user1widthh = (userstatspoints.user_exp / 500) * 100 user1width = floating_decimals(user1widthh, 0) elif 8 <= userstatspoints.user_level <= 10: user1widthh = (userstatspoints.user_exp / 1000) * 100 user1width = floating_decimals(user1widthh, 0) elif 11 <= userstatspoints.user_level <= 14: user1widthh = (userstatspoints.user_exp / 1500) * 100 user1width = floating_decimals(user1widthh, 0) elif 16 <= userstatspoints.user_level <= 20: user1widthh = (userstatspoints.user_exp / 2000) * 100 user1width = floating_decimals(user1widthh, 0) elif 21 <= userstatspoints.user_level <= 25: user1widthh = (userstatspoints.user_exp / 2250) * 100 user1width = floating_decimals(user1widthh, 0) elif 26 <= userstatspoints.user_level <= 30: user1widthh = (userstatspoints.user_exp / 5500) * 100 user1width = floating_decimals(user1widthh, 0) elif 26 <= userstatspoints.user_level <= 30: user1widthh = (userstatspoints.user_exp / 10000) * 100 user1width = floating_decimals(user1widthh, 0) elif 26 <= userstatspoints.user_level <= 30: user1widthh = (userstatspoints.user_exp / 15000) * 100 user1width = floating_decimals(user1widthh, 0) elif 30 <= userstatspoints.user_level <= 50: user1widthh = (userstatspoints.user_exp / 20000) * 100 user1width = floating_decimals(user1widthh, 0) elif 51 <= userstatspoints.user_level <= 100: user1widthh = (userstatspoints.user_exp / 25000) * 100 user1width = floating_decimals(user1widthh, 0) else: user1widthh = (userstatspoints.user_exp / 1000) * 100 user1width = floating_decimals(user1widthh, 0) return user1width
def create_tip_post_bch(subname, postid): """ Creates a bch tip for a post """ form_bch = CreateTipBCH() now = datetime.utcnow() # get the sub, post, comment thesub = db.session\ .query(SubForums)\ .filter(SubForums.subcommon_name == subname)\ .first() post = db.session\ .query(CommonsPost)\ .get(postid) if post.shared_post != 0: idofpost = post.shared_post else: idofpost = post.id if thesub is None: flash("Sub does not exist", category="success") return redirect((request.args.get('next', request.referrer))) if post is None: flash("The post has been removed or doesnt exist", category="success") return redirect((request.args.get('next', request.referrer))) if post.hidden == 1: flash("Post Has been deleted", category="success") return redirect((request.args.get('next', request.referrer))) # get user stats changeuserbchstats = db.session\ .query(UserStatsBCH)\ .filter_by(user_id=current_user.id)\ .first() # get poster stats changeposterbchstats = db.session\ .query(UserStatsBCH)\ .filter_by(user_id=post.content_user_id)\ .first() if request.method == 'POST': if form_bch.validate_on_submit(): # check to see if tipper != poster if post.content_user_id != current_user.id: # get amount donatred getcurrentprice = db.session\ .query(BchPrices)\ .get(1) bch_current_price_usd = getcurrentprice.price usercoinsamount = db.session\ .query(BchWallet)\ .filter(BchWallet.user_id == current_user.id)\ .first() if form_bch.submit.data: seeifcoin = re.compile(btcamount) doesitmatch = seeifcoin.match(form_bch.custom_amount.data) varidoftip = 0 variable_amount = True if doesitmatch: bch_amount_for_submission = Decimal( form_bch.custom_amount.data) decimalform_of_amount = floating_decimals( bch_amount_for_submission, 8) bch_amount = decimalform_of_amount # get usd amount bt = (Decimal(getcurrentprice.price) * bch_amount) formatteddollar = '{0:.2f}'.format(bt) usd_amount = formatteddollar else: flash( "Invalid coin amount. Did you enter the amount wrong?", category="danger") return redirect( url_for('tip.create_tip_post', subname=subname, postid=postid)) elif form_bch.cent.data: bch_amount = Decimal(0.01) / Decimal(bch_current_price_usd) usd_amount = 0.01 varidoftip = 0 variable_amount = True elif form_bch.quarter.data: bch_amount = Decimal(0.25) / Decimal(bch_current_price_usd) usd_amount = 0.25 varidoftip = 0 variable_amount = True elif form_bch.dollar.data: bch_amount = Decimal(1.00) / Decimal(bch_current_price_usd) usd_amount = 1.00 varidoftip = 0 variable_amount = True elif form_bch.five_dollar.data: bch_amount = Decimal(5.00) / Decimal(bch_current_price_usd) usd_amount = 5.00 varidoftip = 0 variable_amount = True elif form_bch.ten_dollar.data: bch_amount = Decimal(10.00) / Decimal( bch_current_price_usd) usd_amount = 10.00 varidoftip = 0 variable_amount = True elif form_bch.twentyfive_dollar.data: bch_amount = Decimal(25.00) / Decimal( bch_current_price_usd) usd_amount = 25.00 varidoftip = 0 variable_amount = True elif form_bch.hundred_dollar.data: bch_amount = Decimal(100.00) / Decimal( bch_current_price_usd) usd_amount = 100.00 varidoftip = 0 variable_amount = True elif form_bch.seven_zero.data: bch_amount = Decimal(0.00000001) usd_amount = 0.00 variable_amount = False varidoftip = 1 elif form_bch.six_zero.data: bch_amount = Decimal(0.00000010) usd_amount = 0.00 varidoftip = 2 variable_amount = False elif form_bch.five_zero.data: bch_amount = Decimal(0.00000100) usd_amount = 0.00 varidoftip = 3 variable_amount = False else: flash("Tip Failure.", category="success") return redirect( url_for('tip.create_tip_post', subname=subname, postid=postid)) final_amount = (floating_decimals(bch_amount, 8)) lowestdonation = 0.00000100 if final_amount >= lowestdonation: percent_to_subowner = 0.07 payout = 1 else: percent_to_subowner = 0 payout = 0 if Decimal(usercoinsamount.currentbalance) >= Decimal( final_amount): if variable_amount is True: # btc amount amount_to_subowner = Decimal(final_amount) * Decimal( percent_to_subowner) # get usd amount subownerbt = (Decimal(getcurrentprice.price) * amount_to_subowner) subownerformatteddollar = '{0:.2f}'.format(subownerbt) subowner_usd_amount = float(subownerformatteddollar) # Btc amount amount_to_poster = Decimal(final_amount) - Decimal( amount_to_subowner) # get usd amount posterbt = (Decimal(getcurrentprice.price) * bch_amount) posterformatteddollar = '{0:.2f}'.format(posterbt) poster_usd_amount = float(posterformatteddollar) else: if varidoftip == 1: # btc_amount = 0.00000001 poster_usd_amount = 0.00 amount_to_poster = Decimal(0.00000001) amount_to_subowner = Decimal(0) subowner_usd_amount = 0.00 elif varidoftip == 2: # btc_amount = 0.00000010 poster_usd_amount = 0.00 amount_to_poster = Decimal(0.00000009) amount_to_subowner = Decimal(0.00000001) subowner_usd_amount = 0.00 elif varidoftip == 3: # btc_amount = 0.00000100 poster_usd_amount = 0.00 amount_to_poster = Decimal(0.00000093) amount_to_subowner = Decimal(0.00000007) subowner_usd_amount = 0.00 else: poster_usd_amount = 0.00 amount_to_poster = Decimal(0.00000000) amount_to_subowner = Decimal(0) subowner_usd_amount = 0.00 if payout == 1: # subowner gets payout newpayout = PayoutSubOwner( created=now, subcommon_id=thesub.id, subcommon_name=thesub.subcommon_name, post_id=post.id, comment_id=0, sub_owner_user_id=thesub.creator_user_id, sub_owner_user_name=thesub.creator_user_name, tipper_user_id=current_user.id, tipper_user_name=current_user.user_name, currency_type=2, amount_bch=amount_to_subowner, amount_usd=subowner_usd_amount, ) db.session.add(newpayout) createnewtip = BchPostTips( created=now, created_user_id=current_user.id, created_user_name=current_user.user_name, recieved_user_id=post.content_user_id, recieved_user_name=post.content_user_name, subcommon_id=thesub.id, subcommon_name=thesub.subcommon_name, post_id=idofpost, amount_bch=amount_to_poster, amount_usd=poster_usd_amount, ) createrecenttip = RecentTips( created=now, created_user_id=current_user.id, created_user_name=current_user.user_name, recieved_user_id=post.content_user_id, recieved_user_name=post.content_user_name, subcommon_id=thesub.id, subcommon_name=thesub.subcommon_name, post_id=idofpost, comment_id=0, currency_type=2, amount_bch=amount_to_poster, amount_usd=poster_usd_amount, ) # add stats to user who donated current_amount_donated_to_comments = changeuserbchstats.total_donated_to_postcomments_bch newamount = (floating_decimals( current_amount_donated_to_comments + final_amount, 8)) changeuserbchstats.total_donated_to_postcomments_bch = newamount current_amount_donated_to_comments_usd = changeuserbchstats.total_donated_to_postcomments_usd newamount_usd = (floating_decimals( current_amount_donated_to_comments_usd + Decimal(usd_amount), 2)) changeuserbchstats.total_donated_to_postcomments_usd = newamount_usd # add stats to user who recieved coin current_amount_recieved_to_posts = changeposterbchstats.total_recievedfromposts_bch newamount_poster = (floating_decimals( current_amount_recieved_to_posts + amount_to_poster, 8)) changeposterbchstats.total_recievedfromposts_bch = newamount_poster current_amount_recieved_to_posts_usd = changeposterbchstats.total_recievedfromposts_usd newamount_poster_usd = (floating_decimals( current_amount_recieved_to_posts_usd + Decimal(poster_usd_amount), 2)) changeposterbchstats.total_recievedfromposts_usd = newamount_poster_usd seeifpostdonates = db.session\ .query(PostDonations)\ .filter(PostDonations.post_id == idofpost)\ .first() if seeifpostdonates is None: addstatstopost = PostDonations( post_id=idofpost, total_recieved_btc=0, total_recieved_btc_usd=0, total_recieved_bch=final_amount, total_recieved_bch_usd=usd_amount, ) db.session.add(addstatstopost) else: # modify comments to show it got btc current_post_bch_amount = seeifpostdonates.total_recieved_bch current_amount_bch_usd_amount = seeifpostdonates.total_recieved_bch_usd newamount_for_post = (floating_decimals( current_post_bch_amount + amount_to_poster, 8)) newamount_for_post_usd = (floating_decimals( current_amount_bch_usd_amount + Decimal(poster_usd_amount), 2)) seeifpostdonates.total_recieved_bch = newamount_for_post seeifpostdonates.total_recieved_bch_usd = newamount_for_post_usd db.session.add(seeifpostdonates) add_new_notification(user_id=post.content_user_id, subid=thesub.id, subname=thesub.subcommon_name, postid=idofpost, commentid=0, msg=20) if payout == 1: add_new_notification(user_id=thesub.creator_user_id, subid=thesub.id, subname=thesub.subcommon_name, postid=post.id, commentid=0, msg=26) # add exp points to donater exppoint(user_id=current_user.id, category=5) # add exp points to reciever exppoint(user_id=post.content_user_id, category=6) # create Wallet Transaction for both users take_coin_from_tipper_bch_post( sender_id=current_user.id, amount=final_amount, postid=idofpost, recieverid=post.content_user_id) # create Wallet Transaction for both users sendcoin_to_poster_bch_post( sender_id=current_user.id, amount=amount_to_poster, postid=idofpost, recieverid=post.content_user_id) if payout == 1: # create Wallet Transaction for both users sendcoin_subowner_bch_post( sender_id=current_user.id, amount=amount_to_subowner, postid=idofpost, recieverid=thesub.creator_user_id) # daily challnge if current_user.is_authenticated: daily_challenge(user_id=current_user.id, category=7) post.last_active = now post.active = 1 db.session.add(createrecenttip) db.session.add(createnewtip) db.session.add(post) db.session.add(changeposterbchstats) db.session.add(changeuserbchstats) db.session.commit() flash("Tip was successful.", category="success") return redirect( url_for('subforum.viewpost', subname=thesub.subcommon_name, postid=post.id)) else: flash("Insufficient Funds.", category="danger") return redirect( url_for('tip.create_tip_post', subname=subname, postid=postid)) else: flash( "Cannot tip yourself. You can promote your posts to boost visibility. ", category="success") return redirect( url_for('subforum.viewpost', subname=thesub.subcommon_name, postid=post.id)) else: flash("Invalid Form", category="success") return redirect( url_for('subforum.viewpost', subname=thesub.subcommon_name, postid=post.id)) return redirect( url_for('subforum.viewpost', subname=thesub.subcommon_name, postid=post.id))
def promotepost_xmr(subname, postid): """ Promotes a post # xmr """ if request.method == 'POST': form_xmr = CreatePromotePostXmr() now = datetime.utcnow() # get the sub, post, comment thesub = db.session.query(SubForums).filter( SubForums.subcommon_name == subname).first() post = db.session.query(CommonsPost).get(postid) # see if user has enough userwallet_xmr = db.session.query(MoneroWallet) userwallet_xmr = userwallet_xmr.filter( MoneroWallet.user_id == current_user.id) userwallet_xmr = userwallet_xmr.first() # get amount donated getcurrentprice_xmr = db.session.query(MoneroPrices).get(1) xmr_current_price_usd = getcurrentprice_xmr.price if post.shared_post != 0: idofpost = post.shared_post else: idofpost = post.id seeifpostpromotions = PostPromotions.query.\ filter(PostPromotions.post_id == idofpost)\ .first() if thesub is None: flash("Sub does not exist.", category="success") return redirect(url_for('index')) if post is None: flash("Post does not exist.", category="success") return redirect( url_for('subforum.sub', subname=thesub.subcommon_name)) if post.hidden == 1: flash("Post has been removed.", category="success") return redirect( url_for('subforum.sub', subname=thesub.subcommon_name)) # get user stats if form_xmr.validate_on_submit(): if form_xmr.submit.data: seeifcoin = re.compile(btcamount) doesitmatch = seeifcoin.match(form_xmr.custom_amount.data) if doesitmatch: xmr_amount_for_submission = Decimal( form_xmr.custom_amount.data) decimalform_of_amount = floating_decimals( xmr_amount_for_submission, 12) xmr_amount = decimalform_of_amount # get usd amount getcurrentprice = db.session.query(MoneroPrices).get(1) bt = (Decimal(getcurrentprice.price) * xmr_amount) formatteddollar = '{0:.2f}'.format(bt) usd_amount = formatteddollar else: flash( "Invalid Amount. Did you not enter the amount correctly?", category="danger") return redirect( url_for('promote.promotepost', subname=subname, postid=postid)) elif form_xmr.cent_xmr.data: xmr_amount = Decimal(0.01) / Decimal(xmr_current_price_usd) usd_amount = 0.01 elif form_xmr.quarter_xmr.data: xmr_amount = Decimal(0.25) / Decimal(xmr_current_price_usd) usd_amount = 0.25 elif form_xmr.dollar_xmr.data: xmr_amount = Decimal(1.00) / Decimal(xmr_current_price_usd) usd_amount = 1.00 elif form_xmr.five_dollar_xmr.data: xmr_amount = Decimal(5.00) / Decimal(xmr_current_price_usd) usd_amount = 5.00 elif form_xmr.ten_dollar_xmr.data: xmr_amount = Decimal(10.00) / Decimal(xmr_current_price_usd) usd_amount = 10.00 elif form_xmr.twentyfive_dollar_xmr.data: xmr_amount = Decimal(25.00) / Decimal(xmr_current_price_usd) usd_amount = 25.00 elif form_xmr.hundred_dollar_xmr.data: xmr_amount = Decimal(100.00) / Decimal(xmr_current_price_usd) usd_amount = 100.00 else: flash("Post Promotion Failure.", category="success") return redirect(url_for('index')) final_amount_xmr = (floating_decimals(xmr_amount, 12)) if Decimal(userwallet_xmr.currentbalance) >= Decimal(xmr_amount): if final_amount_xmr > 0: createnewpomotion = PostPromote( created=now, created_user_id=current_user.id, created_user_name=current_user.user_name, subcommon_id=thesub.id, subcommon_name=thesub.subcommon_name, post_id=idofpost, amount_bch=0, amount_btc=0, amount_xmr=final_amount_xmr, amount_usd=usd_amount) db.session.add(createnewpomotion) db.session.commit() changeuserxmrstats = db.session.query(UserStatsXMR)\ .filter_by(user_id=current_user.id)\ .first() # add stats to user who donated # coin current_amount_donated_to_posts = changeuserxmrstats.total_donated_to_postcomments_xmr newamount = (floating_decimals( current_amount_donated_to_posts + final_amount_xmr, 12)) changeuserxmrstats.total_donated_to_postcomments_xmr = newamount # usd current_amount_donated_to_posts_usd = changeuserxmrstats.total_donated_to_postcomments_usd newamount_usd = (floating_decimals( current_amount_donated_to_posts_usd + Decimal(usd_amount), 2)) changeuserxmrstats.total_donated_to_postcomments_usd = newamount_usd if seeifpostpromotions is None: addstatstopost = PostPromotions( post_id=idofpost, total_recieved_bch=0, total_recieved_bch_usd=0, total_recieved_btc=0, total_recieved_btc_usd=0, total_recieved_xmr=final_amount_xmr, total_recieved_xmr_usd=usd_amount, ) db.session.add(addstatstopost) else: # modify post to show it got xmr current_post_xmr_amount = seeifpostpromotions.total_recieved_xmr current_amount_xmr_usd_amount = seeifpostpromotions.total_recieved_xmr_usd newamount_for_post = (floating_decimals( current_post_xmr_amount + final_amount_xmr, 12)) newamount_for_post_usd = (floating_decimals( current_amount_xmr_usd_amount + Decimal(usd_amount), 2)) # set post to active and update post seeifpostpromotions.total_recieved_xmr = newamount_for_post seeifpostpromotions.total_recieved_xmr_usd = newamount_for_post_usd db.session.add(seeifpostpromotions) # create Wallet Transaction for both users sendcointosite_post_promotion_xmr( sender_id=current_user.id, amount=final_amount_xmr, postid=postid, room=subname) post.active = 1 post.last_active = now db.session.add(post) db.session.add(changeuserxmrstats) # daily challnge if current_user.is_authenticated: daily_challenge(user_id=current_user.id, category=6) # send notification you got a coin promotion add_new_notification( user_id=post.poster_user_id, subid=post.subcommon_id, subname=post.subcommon_name, postid=post.id, commentid=0, msg=62, ) db.session.commit() flash( "Successfully Promoted Post with Monero. In a few minutes the score will be updated.", category="success") return redirect( url_for('subforum.viewpost', subname=thesub.subcommon_name, postid=post.id)) else: flash("Invalid Amount.", category="danger") return redirect( url_for('promote.promotepost', subname=subname, postid=postid)) else: flash("Not enough coin in your wallet.", category="danger") return redirect( url_for('promote.promotepost', subname=subname, postid=postid)) else: flash("Invalid Amount.", category="danger") return redirect( url_for('promote.promotepost', subname=subname, postid=postid))
def sendcoin(): # forms form = WalletSendCoin() # Get wallet wallet = db.session.query(MoneroWallet).filter_by( user_id=current_user.id).first() # walletfee walletthefee = db.session.query(MoneroWalletFee).get(1) wfee = Decimal(walletthefee.amount) if request.method == "POST": if form.validate_on_submit(): if User.decryptpassword(pwdhash=current_user.wallet_pin, password=form.pin.data): sendto = form.sendto.data comment = form.description.data amount = form.amount.data # test wallet_btc stuff for security walbal = Decimal(wallet.currentbalance) amount2withfee = Decimal(amount) + Decimal(wfee) # greater than amount with fee if floating_decimals(walbal, 8) >= floating_decimals( amount2withfee, 8): # greater than fee if Decimal(amount) > Decimal(wfee): # add to wallet_btc work monerosendcoin( user_id=current_user.id, sendto=sendto, amount=amount, ) flash("XMR Sent: " + str(sendto), category="success") flash( "Please allow a few minutes for the transaction to appear and process to begin.", category="success") return redirect( url_for('wallet_xmr.home', user_name=current_user.user_name)) else: flash( "Cannot withdraw amount less than wallet_btc fee: " + str(wfee), category="danger") return redirect( url_for('wallet_xmr.home', user_name=current_user.user_name)) else: flash("Cannot withdraw amount less than wallet_btc fee: " + str(wfee), category="danger") return redirect( url_for('wallet_xmr.home', user_name=current_user.user_name)) else: flash("Invalid Pin.", category="danger") return redirect( url_for('wallet_xmr.home', user_name=current_user.user_name)) else: flash("Bad Form. Did you enter the information correctly?", category="danger") return redirect( url_for('wallet_xmr.home', user_name=current_user.user_name))
def daily_challenge(user_id, category): from app import db from app.classes.user import User, DailyChallenge, UserDailyChallenge from datetime import datetime from app.common.functions import floating_decimals from app.wallet_bch.wallet_btccash_daily import sendcoin_user_daily_bch from app.wallet_btc.wallet_btc_daily import sendcoin_user_daily_btc from app.wallet_xmr.wallet_xmr_daily import sendcoin_user_daily_xmr # category 1 = post something # category 2 = comment on a post # category 3 = vote on a post # category 4 = vote on a comment getuserdaily = db.session.query(UserDailyChallenge)\ .filter(UserDailyChallenge.user_id == user_id)\ .all() list_of_challenges = [] for f in getuserdaily: list_of_challenges.append(f.category_of_challenge) if category in list_of_challenges: the_challenge = db.session.query(UserDailyChallenge)\ .filter(UserDailyChallenge.user_id == user_id, UserDailyChallenge.category_of_challenge == category)\ .first() if the_challenge.completed == 0: new_number_to_complete = the_challenge.current_number_of_times + 1 the_challenge.current_number_of_times = new_number_to_complete # Calculate width to next level width_calculator_full = (the_challenge.current_number_of_times / the_challenge.how_many_to_complete) * 100 width_calculator = floating_decimals(width_calculator_full, 0) the_challenge.user_width_next_level = width_calculator # see if user completed the daily missions if the_challenge.current_number_of_times == the_challenge.how_many_to_complete: # make the challenge completed the_challenge.completed = 1 # send the coin # if bitcoin if the_challenge.reward_coin == 1: sendcoin_user_daily_btc(user_id=user_id, amount=the_challenge.reward_amount) # if bitcoin cash elif the_challenge.reward_coin == 2: sendcoin_user_daily_bch(user_id=user_id, amount=the_challenge.reward_amount) # if monero elif the_challenge.reward_coin == 3: sendcoin_user_daily_xmr(user_id=user_id, amount=the_challenge.reward_amount) else: pass # add to db db.session.add(the_challenge) db.session.flush()