From 12758c5bb50b171bd048d084f165204e4b514ab8 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Wed, 18 Jan 2023 22:41:16 -0800 Subject: [PATCH] get tip processing working better --- .gitignore | 1 + export.py | 9 +++++++-- suchwow/_models.py | 11 +++++++++- suchwow/cli.py | 50 +++++++++++++++++++++++++++------------------- suchwow/wownero.py | 13 +++++------- 5 files changed, 53 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index b3b4ba6..b92a399 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ __pycache__ *sql flask_session .env +.env.dev diff --git a/export.py b/export.py index 1ddb920..0521519 100755 --- a/export.py +++ b/export.py @@ -42,10 +42,15 @@ for post in all_posts: 'to_reddit': post.to_reddit, 'to_discord': post.to_discord, 'approved': post.approved, - 'txes': wallet.transfers(post.account_index) + 'txes': wallet.make_wallet_rpc('get_transfers', { + 'account_index': post.account_index, + 'subaddr_indices': [], + 'in': True, + 'out': True + }) } all_data['posts'].append(post_data) - print(post_data['txes']) + print(f'Exporting post {post.id}') for mod in all_mods: all_data['moderators'].append(mod.username) diff --git a/suchwow/_models.py b/suchwow/_models.py index e737764..7ca2552 100644 --- a/suchwow/_models.py +++ b/suchwow/_models.py @@ -38,7 +38,7 @@ class User(Model): def get_wow_sent(self): tips = TipSent.select().where(TipSent.from_user == self) - return sum(tip.amount for tip in tips) + return sum(tip.amount for tip in tips) + sum(tip.fee for tip in tips) def get_post_count(self): posts = Post.select().where(Post.user == self) @@ -137,6 +137,15 @@ class Post(Model): database = db +class SocialPost(Model): + id = AutoField() + post = ForeignKeyField(Post) + service = CharField() + + class Meta: + database = db + + class Vote(Model): id = AutoField() post = ForeignKeyField(Post) diff --git a/suchwow/cli.py b/suchwow/cli.py index 95c0239..fd5a8d1 100644 --- a/suchwow/cli.py +++ b/suchwow/cli.py @@ -55,25 +55,35 @@ def generate_data(): @bp.cli.command('process_tips') def process_tips(): w = wownero.Wallet() - txes = w.transfers([], True, False) - for tx in txes['in']: - _tx = TipReceived.select().where(TipReceived.txid == tx['txid']).first() - if not _tx: - post = Post.select().where(Post.address == tx['address']).first() - if not post: - print('No post exists with that address. Not sure wat do.') - else: - TipReceived.create( - post=post, - txid=tx['txid'], - timestamp=datetime.utcfromtimestamp(tx['timestamp']), - amount=sum(tx['amounts']), - fee=tx['fee'] - ) - print('Saved tip {} ({} WOW) received for post {} by {}'.format( - tx['txid'], wownero.from_atomic(sum(tx['amounts'])), - post.id, post.user.username - )) + for post in Post.select().order_by(Post.timestamp.desc()): + print(f'Checking new tips for post {post.id}') + txes = w.transfers(config.WALLET_ACCOUNT, [post.address_index]) + addr = w.get_address(config.WALLET_ACCOUNT, [post.address_index]) + if post.address != addr['addresses'][0]['address']: + print(f'addresses dont match. skipping.') + continue + if txes: + for tx in txes['in']: + if tx['unlock_time'] > 0: + print('someone added a lock time to this tx. skipping for now.') + continue + _tx = TipReceived.select().where(TipReceived.txid == tx['txid']).first() + if not _tx: + post = Post.select().where(Post.address == tx['address']).first() + if not post: + print('No post exists with that address. Not sure wat do.') + else: + TipReceived.create( + post=post, + txid=tx['txid'], + timestamp=datetime.utcfromtimestamp(tx['timestamp']), + amount=sum(tx['amounts']), + fee=tx['fee'] + ) + print('Saved tip {} ({} WOW) received for post {} by {}'.format( + tx['txid'], wownero.from_atomic(sum(tx['amounts'])), + post.id, post.user.username + )) @bp.cli.command('payout_users') def payout_users(): @@ -86,7 +96,7 @@ def payout_users(): rcvd = user.get_wow_received() sent = user.get_wow_sent() to_send = rcvd - sent - if to_send: + if to_send >= 1: print('{} has received {} atomic WOW but sent {} atomic WOW. Sending {} atomic WOW'.format( user.username, wownero.from_atomic(rcvd), wownero.from_atomic(sent), wownero.from_atomic(to_send) diff --git a/suchwow/wownero.py b/suchwow/wownero.py index e48f173..4584062 100644 --- a/suchwow/wownero.py +++ b/suchwow/wownero.py @@ -67,22 +67,19 @@ class Wallet(object): addresses[_addr['address_index']] = _addr['address'] return addresses - def get_address(self, account): - qdata = {'account_index': account} + def get_address(self, account, address_indices=[]): + qdata = {'account_index': account, 'address_index': address_indices} _addresses = self.make_wallet_rpc('get_address', qdata) - if 'address' in _addresses: - return _addresses['address'] - else: - return None + return _addresses def new_address(self, account, label=None): data = {'account_index': account, 'label': label} _address = self.make_wallet_rpc('create_address', data) return (_address['address_index'], _address['address']) - def transfers(self, address_indices=[], _in=True, _out=True): + def transfers(self, account_index=0, address_indices=[], _in=True, _out=True): data = { - 'account_index': config.WALLET_ACCOUNT, + 'account_index': account_index, 'subaddr_indices': address_indices, 'in': _in, 'out': _out