mirror of
https://git.wownero.com/lza_menace/suchwow.git
synced 2024-08-15 01:03:19 +00:00
get tip processing working better
This commit is contained in:
parent
b250ba7460
commit
12758c5bb5
5 changed files with 53 additions and 31 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@ __pycache__
|
||||||
*sql
|
*sql
|
||||||
flask_session
|
flask_session
|
||||||
.env
|
.env
|
||||||
|
.env.dev
|
||||||
|
|
|
@ -42,10 +42,15 @@ for post in all_posts:
|
||||||
'to_reddit': post.to_reddit,
|
'to_reddit': post.to_reddit,
|
||||||
'to_discord': post.to_discord,
|
'to_discord': post.to_discord,
|
||||||
'approved': post.approved,
|
'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)
|
all_data['posts'].append(post_data)
|
||||||
print(post_data['txes'])
|
print(f'Exporting post {post.id}')
|
||||||
|
|
||||||
for mod in all_mods:
|
for mod in all_mods:
|
||||||
all_data['moderators'].append(mod.username)
|
all_data['moderators'].append(mod.username)
|
||||||
|
|
|
@ -38,7 +38,7 @@ class User(Model):
|
||||||
|
|
||||||
def get_wow_sent(self):
|
def get_wow_sent(self):
|
||||||
tips = TipSent.select().where(TipSent.from_user == 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):
|
def get_post_count(self):
|
||||||
posts = Post.select().where(Post.user == self)
|
posts = Post.select().where(Post.user == self)
|
||||||
|
@ -137,6 +137,15 @@ class Post(Model):
|
||||||
database = db
|
database = db
|
||||||
|
|
||||||
|
|
||||||
|
class SocialPost(Model):
|
||||||
|
id = AutoField()
|
||||||
|
post = ForeignKeyField(Post)
|
||||||
|
service = CharField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
database = db
|
||||||
|
|
||||||
|
|
||||||
class Vote(Model):
|
class Vote(Model):
|
||||||
id = AutoField()
|
id = AutoField()
|
||||||
post = ForeignKeyField(Post)
|
post = ForeignKeyField(Post)
|
||||||
|
|
|
@ -55,25 +55,35 @@ def generate_data():
|
||||||
@bp.cli.command('process_tips')
|
@bp.cli.command('process_tips')
|
||||||
def process_tips():
|
def process_tips():
|
||||||
w = wownero.Wallet()
|
w = wownero.Wallet()
|
||||||
txes = w.transfers([], True, False)
|
for post in Post.select().order_by(Post.timestamp.desc()):
|
||||||
for tx in txes['in']:
|
print(f'Checking new tips for post {post.id}')
|
||||||
_tx = TipReceived.select().where(TipReceived.txid == tx['txid']).first()
|
txes = w.transfers(config.WALLET_ACCOUNT, [post.address_index])
|
||||||
if not _tx:
|
addr = w.get_address(config.WALLET_ACCOUNT, [post.address_index])
|
||||||
post = Post.select().where(Post.address == tx['address']).first()
|
if post.address != addr['addresses'][0]['address']:
|
||||||
if not post:
|
print(f'addresses dont match. skipping.')
|
||||||
print('No post exists with that address. Not sure wat do.')
|
continue
|
||||||
else:
|
if txes:
|
||||||
TipReceived.create(
|
for tx in txes['in']:
|
||||||
post=post,
|
if tx['unlock_time'] > 0:
|
||||||
txid=tx['txid'],
|
print('someone added a lock time to this tx. skipping for now.')
|
||||||
timestamp=datetime.utcfromtimestamp(tx['timestamp']),
|
continue
|
||||||
amount=sum(tx['amounts']),
|
_tx = TipReceived.select().where(TipReceived.txid == tx['txid']).first()
|
||||||
fee=tx['fee']
|
if not _tx:
|
||||||
)
|
post = Post.select().where(Post.address == tx['address']).first()
|
||||||
print('Saved tip {} ({} WOW) received for post {} by {}'.format(
|
if not post:
|
||||||
tx['txid'], wownero.from_atomic(sum(tx['amounts'])),
|
print('No post exists with that address. Not sure wat do.')
|
||||||
post.id, post.user.username
|
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')
|
@bp.cli.command('payout_users')
|
||||||
def payout_users():
|
def payout_users():
|
||||||
|
@ -86,7 +96,7 @@ def payout_users():
|
||||||
rcvd = user.get_wow_received()
|
rcvd = user.get_wow_received()
|
||||||
sent = user.get_wow_sent()
|
sent = user.get_wow_sent()
|
||||||
to_send = rcvd - 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(
|
print('{} has received {} atomic WOW but sent {} atomic WOW. Sending {} atomic WOW'.format(
|
||||||
user.username, wownero.from_atomic(rcvd),
|
user.username, wownero.from_atomic(rcvd),
|
||||||
wownero.from_atomic(sent), wownero.from_atomic(to_send)
|
wownero.from_atomic(sent), wownero.from_atomic(to_send)
|
||||||
|
|
|
@ -67,22 +67,19 @@ class Wallet(object):
|
||||||
addresses[_addr['address_index']] = _addr['address']
|
addresses[_addr['address_index']] = _addr['address']
|
||||||
return addresses
|
return addresses
|
||||||
|
|
||||||
def get_address(self, account):
|
def get_address(self, account, address_indices=[]):
|
||||||
qdata = {'account_index': account}
|
qdata = {'account_index': account, 'address_index': address_indices}
|
||||||
_addresses = self.make_wallet_rpc('get_address', qdata)
|
_addresses = self.make_wallet_rpc('get_address', qdata)
|
||||||
if 'address' in _addresses:
|
return _addresses
|
||||||
return _addresses['address']
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def new_address(self, account, label=None):
|
def new_address(self, account, label=None):
|
||||||
data = {'account_index': account, 'label': label}
|
data = {'account_index': account, 'label': label}
|
||||||
_address = self.make_wallet_rpc('create_address', data)
|
_address = self.make_wallet_rpc('create_address', data)
|
||||||
return (_address['address_index'], _address['address'])
|
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 = {
|
data = {
|
||||||
'account_index': config.WALLET_ACCOUNT,
|
'account_index': account_index,
|
||||||
'subaddr_indices': address_indices,
|
'subaddr_indices': address_indices,
|
||||||
'in': _in,
|
'in': _in,
|
||||||
'out': _out
|
'out': _out
|
||||||
|
|
Loading…
Reference in a new issue