From 3e087646f5d23b637295f7af0a132e3fac8e9a7d Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 3 Oct 2022 11:01:37 -0700 Subject: [PATCH] idk, mo shit --- xmrbackers/helpers.py | 16 +--------------- xmrbackers/routes/creator.py | 31 ++++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/xmrbackers/helpers.py b/xmrbackers/helpers.py index d355546..0973e2e 100644 --- a/xmrbackers/helpers.py +++ b/xmrbackers/helpers.py @@ -1,24 +1,10 @@ import peewee as pw import playhouse.postgres_ext as pwpg from monero.wallet import Wallet -# from monero.exceptions import WrongAddress from xmrbackers import config -# def check_tx_key(tx_id, tx_key, wallet_address): -# try: -# check_data = { -# 'txid': tx_id, -# 'tx_key': tx_key, -# 'address': wallet_address -# } -# w = Wallet(port=config.XMR_WALLET_RPC_PORT, user=config.XMR_WALLET_RPC_USER, password=config.XMR_WALLET_RPC_PASS) -# res = w._backend.raw_request('check_tx_key', check_data) -# return res -# except: -# raise Exception('there was a problem i dont feel like writing good code for right now') - def make_wallet_rpc(method, data={}): try: w = Wallet( @@ -30,7 +16,7 @@ def make_wallet_rpc(method, data={}): res = w._backend.raw_request(method, data) return res except Exception as e: - raise Exception('there was a problem i dont feel like writing good code for right now', e) + raise e class EnumArrayField(pwpg.ArrayField): diff --git a/xmrbackers/routes/creator.py b/xmrbackers/routes/creator.py index ca00c4c..95677f1 100644 --- a/xmrbackers/routes/creator.py +++ b/xmrbackers/routes/creator.py @@ -1,8 +1,9 @@ -from quart import Blueprint, render_template, flash, redirect, url_for +from quart import Blueprint, render_template, flash, redirect, url_for, request from flask_login import current_user, login_required from monero.wallet import Wallet from monero.address import address from monero.numbers import to_atomic, from_atomic +from monero.backends.jsonrpc.exceptions import RPCError from xmrbackers.models import * from xmrbackers.helpers import make_wallet_rpc @@ -114,21 +115,37 @@ async def show(handle): await flash('That creator does not exist.', 'warning') return redirect(url_for('main.index')) - if form.validate_on_submit(): - await flash('valid form submission', 'success') - posts = Content.select().where( Content.creator == creator, Content.hidden == False ).order_by(Content.post_date.desc()) - subscription = SubscriptionMeta.select().where( + subscriptions = SubscriptionMeta.select().where( SubscriptionMeta.user == creator - ).order_by(SubscriptionMeta.create_date.desc()).first() + ).order_by(SubscriptionMeta.create_date.desc()) + + if form.validate_on_submit(): + data = { + 'txid': form.tx_id.data, + 'tx_key': form.tx_key.data, + 'address': form.wallet_address.data + } + try: + res = make_wallet_rpc('check_tx_key', data) + subs = subscriptions.where( + SubscriptionMeta.wallet_address == data['address'] + ) + for sub in subs: + if res['in_pool'] is False and res['received'] >= sub.atomic_xmr: + await flash('Found a valid subscription.', 'success') + print(request) + return redirect(url_for('creator.show', handle=handle)) + except RPCError: + await flash('Failed to check TX Key. Problem with provided info.', 'error') return await render_template( 'creator/show.html', creator=creator, - subscription=subscription, + subscription=subscriptions.first(), posts=posts, form=form )