get tip processing working better

migrate-new-models
lza_menace 2 years ago
parent b250ba7460
commit 12758c5bb5

1
.gitignore vendored

@ -7,3 +7,4 @@ __pycache__
*sql
flask_session
.env
.env.dev

@ -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)

@ -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)

@ -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)

@ -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

Loading…
Cancel
Save