reworking payout logic

This commit is contained in:
lza_menace 2022-09-06 00:50:26 -07:00
parent 1624439bba
commit b250ba7460
2 changed files with 55 additions and 46 deletions

View file

@ -1,5 +1,6 @@
from os import makedirs, getenv
from random import choice
from datetime import datetime
import lorem
from flask import Blueprint
@ -51,6 +52,47 @@ 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
))
@bp.cli.command('payout_users')
def payout_users():
wallet = wownero.Wallet()
balances = wallet.balances()
print('Wallet balances are {} locked, {} unlocked'.format(
wownero.from_atomic(balances[0]), wownero.from_atomic(balances[1])
))
for user in User.select():
rcvd = user.get_wow_received()
sent = user.get_wow_sent()
to_send = rcvd - sent
if to_send:
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)
))
@bp.cli.command('rescan')
def rescan():
@ -75,22 +117,6 @@ def create_accounts():
print(f"Created account {account}")
wallet.make_wallet_rpc('store')
# @bp.cli.command("post_reddit")
# @click.argument('last_hours')
# def post_reddit(last_hours):
# posts = Post.select().where(
# Post.approved==True,
# Post.to_reddit==False
# ).order_by(Post.timestamp.asc())
# for p in posts:
# if p.hours_elapsed() < int(last_hours):
# if not p.to_reddit:
# _p = make_post(p)
# if _p:
# p.to_reddit = True
# p.save()
# return
# @bp.cli.command("payout_users")
# def payout_users():

View file

@ -47,15 +47,6 @@ class Wallet(object):
def height(self):
return self.make_wallet_rpc('get_height', {})
def spend_key(self):
return self.make_wallet_rpc('query_key', {'key_type': 'spend_key'})['key']
def view_key(self):
return self.make_wallet_rpc('query_key', {'key_type': 'view_key'})['key']
def seed(self):
return self.make_wallet_rpc('query_key', {'key_type': 'mnemonic'})['key']
def accounts(self):
_accounts = self.make_wallet_rpc('get_accounts')
return [i['account_index'] for i in _accounts['subaddress_accounts']]
@ -89,20 +80,23 @@ class Wallet(object):
_address = self.make_wallet_rpc('create_address', data)
return (_address['address_index'], _address['address'])
def transfers(self, account, address_indices=[]):
def transfers(self, address_indices=[], _in=True, _out=True):
data = {
'account_index': account,
'account_index': config.WALLET_ACCOUNT,
'subaddr_indices': address_indices,
'in': True,
'out': True
'in': _in,
'out': _out
}
_transfers = self.make_wallet_rpc('get_transfers', data)
return _transfers
def balances(self, account):
data = {'account_index': account}
def balances(self, address_indices=[]):
data = {
'account_index': config.WALLET_ACCOUNT,
'address_indices': address_indices
}
_balance = self.make_wallet_rpc('get_balance', data)
return (from_atomic(_balance['balance']), from_atomic(_balance['unlocked_balance']))
return (_balance['balance'], _balance['unlocked_balance'])
def transfer(self, dest_address, amount, priority, account):
data = {
@ -120,26 +114,15 @@ class Wallet(object):
self.store()
return transfer
def sweep_all(self, account, dest_address):
data = {
'address': dest_address,
'account_index': account,
}
sweep = self.make_wallet_rpc('sweep_all', data)
self.store()
return sweep
def incoming_transfers(self, account, transfer_type='all', verbose=True):
def incoming_transfers(self, transfer_type='all'):
data = {
'transfer_type': transfer_type,
'account_index': account,
'verbose': verbose
'account_index': config.WALLET_ACCOUNT
}
transfers = self.make_wallet_rpc('incoming_transfers', data)
return transfers
def to_atomic(amount):
if not isinstance(amount, (Decimal, float) + six.integer_types):
raise ValueError("Amount '{}' doesn't have numeric type. Only Decimal, int, long and "