mirror of
https://git.wownero.com/lza_menace/suchwow.git
synced 2024-08-15 01:03:19 +00:00
update payout logic
This commit is contained in:
parent
159504f703
commit
90377f8d0a
2 changed files with 49 additions and 5 deletions
|
@ -34,15 +34,19 @@ class User(Model):
|
||||||
|
|
||||||
def get_wow_received(self):
|
def get_wow_received(self):
|
||||||
tips = TipReceived.select().join(Post).where(Post.user == self)
|
tips = TipReceived.select().join(Post).where(Post.user == self)
|
||||||
return sum(tip.amount for tip in tips)
|
return sum([tip.amount for tip in tips])
|
||||||
|
|
||||||
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) + sum(tip.fee for tip in tips)
|
return sum([tip.amount + 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)
|
||||||
return posts.count()
|
return posts.count()
|
||||||
|
|
||||||
|
def get_post_addresses(self):
|
||||||
|
posts = Post.select().where(Post.user == self)
|
||||||
|
return [i.address_index for i in posts]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
database = db
|
database = db
|
||||||
|
@ -157,7 +161,8 @@ class Post(Model):
|
||||||
'approved_by': self.approved_by,
|
'approved_by': self.approved_by,
|
||||||
'received_wow': self.get_wow_received(),
|
'received_wow': self.get_wow_received(),
|
||||||
'hours_elapsed': self.hours_elapsed(),
|
'hours_elapsed': self.hours_elapsed(),
|
||||||
'tips_received': [tip for tip in TipReceived.select().where(TipReceived.post == self)]
|
'user_tips_received': wownero.from_atomic(self.user.get_wow_received()),
|
||||||
|
'user_tips_sent': wownero.from_atomic(self.user.get_wow_sent())
|
||||||
}
|
}
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -86,6 +86,7 @@ def process_tips():
|
||||||
post.id, post.user.username
|
post.id, post.user.username
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
@bp.cli.command('payout_users')
|
@bp.cli.command('payout_users')
|
||||||
def payout_users():
|
def payout_users():
|
||||||
wallet = wownero.Wallet()
|
wallet = wownero.Wallet()
|
||||||
|
@ -93,15 +94,53 @@ def payout_users():
|
||||||
print('Wallet balances are {} locked, {} unlocked'.format(
|
print('Wallet balances are {} locked, {} unlocked'.format(
|
||||||
wownero.from_atomic(balances[0]), wownero.from_atomic(balances[1])
|
wownero.from_atomic(balances[0]), wownero.from_atomic(balances[1])
|
||||||
))
|
))
|
||||||
for user in User.select():
|
for user in User.select().join(Post, on=Post.user).distinct().order_by(User.id.asc()):
|
||||||
rcvd = user.get_wow_received()
|
rcvd = user.get_wow_received()
|
||||||
sent = user.get_wow_sent()
|
sent = user.get_wow_sent()
|
||||||
|
if rcvd == 0:
|
||||||
|
continue
|
||||||
to_send = rcvd - sent
|
to_send = rcvd - sent
|
||||||
if to_send >= 1:
|
if to_send >= wownero.to_atomic(.5):
|
||||||
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)
|
||||||
))
|
))
|
||||||
|
if balances[1] >= to_send:
|
||||||
|
tx_data = {
|
||||||
|
'account_index': config.WALLET_ACCOUNT,
|
||||||
|
'destinations': [{
|
||||||
|
'address': user.address,
|
||||||
|
'amount': to_send
|
||||||
|
}],
|
||||||
|
'subaddress_indices': user.get_post_addresses(),
|
||||||
|
'priority': 0,
|
||||||
|
'unlock_time': 0,
|
||||||
|
'get_tx_key': True,
|
||||||
|
'do_not_relay': True,
|
||||||
|
'ring_size': 22
|
||||||
|
}
|
||||||
|
transfer = wallet.make_wallet_rpc('transfer', tx_data)
|
||||||
|
print(transfer)
|
||||||
|
if 'code' in transfer:
|
||||||
|
return
|
||||||
|
tx_data['destinations'][0]['amount'] = to_send - transfer['fee']
|
||||||
|
tx_data['do_not_relay'] = False
|
||||||
|
transfer = wallet.make_wallet_rpc('transfer', tx_data)
|
||||||
|
print(tx_data)
|
||||||
|
print(transfer)
|
||||||
|
if 'code' in transfer:
|
||||||
|
return
|
||||||
|
TipSent.create(
|
||||||
|
from_user=user,
|
||||||
|
to_user=user,
|
||||||
|
txid=transfer['tx_hash'],
|
||||||
|
timestamp=datetime.utcnow(),
|
||||||
|
amount=transfer['amount'],
|
||||||
|
fee=transfer['fee'],
|
||||||
|
)
|
||||||
|
print(f'Sent tip of {wownero.from_atomic(transfer["amount"])} WOW to {user} in tx_hash {transfer["tx_hash"]}')
|
||||||
|
wallet.make_wallet_rpc('store')
|
||||||
|
|
||||||
|
|
||||||
@bp.cli.command('fix_image')
|
@bp.cli.command('fix_image')
|
||||||
@click.argument('post_id')
|
@click.argument('post_id')
|
||||||
|
|
Loading…
Reference in a new issue