From d7f8321e2858cf7c4e0172d1e82c27cca783b6e4 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Thu, 8 Dec 2022 20:37:22 -0800 Subject: [PATCH] finalize tip verification --- nerochan/cli.py | 15 +++++++++++---- nerochan/models.py | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/nerochan/cli.py b/nerochan/cli.py index 1a9c9ce..34d999f 100644 --- a/nerochan/cli.py +++ b/nerochan/cli.py @@ -6,6 +6,8 @@ from datetime import datetime, timedelta, timezone from os import path, makedirs from urllib.request import urlopen +from monero.exceptions import TransactionNotFound + from nerochan.helpers import make_wallet_rpc, get_daemon from nerochan.models import User, Artwork, Transaction @@ -48,7 +50,7 @@ def cli(app): @app.cli.command('verify_tips') def verify_tips(): - txes = Transaction.select() + txes = Transaction.select().where(Transaction.verified == False) for tx in txes: data = { 'txid': tx.tx_id, @@ -57,6 +59,7 @@ def cli(app): } try: res = make_wallet_rpc('check_tx_key', data) + print(res) if res['received'] == 0: click.echo(f'[tx-{tx.id}] Key and tx are correct, but found XMR amount of 0. User must have selected the wrong post.') continue @@ -68,10 +71,14 @@ def cli(app): tx.verified = True tx.save() click.echo(f'[+] Found valid tip {tx.tx_id}') + except TransactionNotFound as e: + print(f'Transaction not found for tx #{tx.id}: {tx.tx_id}') except Exception as e: - # delete if it fails for over 8 hours - if tx.create_date <= datetime.utcnow() - timedelta(hours=8): - pass + print(f'Error for tx #{tx.id}: {e}') + finally: + # just delete it if older than 12 hours + if tx.create_date <= datetime.utcnow() - timedelta(hours=12): + tx.delete_instance() @app.cli.command('generate_data') def generate_data(): diff --git a/nerochan/models.py b/nerochan/models.py index 8f8df23..3309e82 100644 --- a/nerochan/models.py +++ b/nerochan/models.py @@ -165,7 +165,7 @@ class Transaction(pw.Model): tx_key = pw.CharField(unique=True) atomic_xmr = pw.BigIntegerField(null=True) to_address = pw.CharField() - artwork = pw.ForeignKeyField(Artwork) + artwork = pw.ForeignKeyField(Artwork, backref='tips') verified = pw.BooleanField(default=False) create_date = pw.DateTimeField(default=datetime.utcnow) tx_date = pw.DateTimeField(null=True)