|
|
@ -1,10 +1,11 @@
|
|
|
|
from quart import Blueprint, render_template, flash, redirect, url_for
|
|
|
|
from quart import Blueprint, render_template, flash, redirect, url_for
|
|
|
|
from flask_login import current_user, login_required
|
|
|
|
from flask_login import current_user, login_required
|
|
|
|
from monero.wallet import Wallet
|
|
|
|
from monero.wallet import Wallet
|
|
|
|
|
|
|
|
from monero.address import address
|
|
|
|
|
|
|
|
from monero.numbers import to_atomic, from_atomic
|
|
|
|
|
|
|
|
|
|
|
|
from xmrbackers.models import User, Profile, Content
|
|
|
|
from xmrbackers.models import *
|
|
|
|
from xmrbackers.models import Subscription, SubscriptionMeta, UserRole
|
|
|
|
from xmrbackers.helpers import make_wallet_rpc
|
|
|
|
from xmrbackers.helpers import check_tx_key
|
|
|
|
|
|
|
|
from xmrbackers import config, forms
|
|
|
|
from xmrbackers import config, forms
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -19,42 +20,107 @@ async def all():
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return await render_template('creator/creators.html', creators=creators)
|
|
|
|
return await render_template('creator/creators.html', creators=creators)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/creators/join')
|
|
|
|
@bp.route('/creators/join', methods=['GET', 'POST'])
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
async def join():
|
|
|
|
async def join():
|
|
|
|
form = forms.ConfirmCreatorSubscription()
|
|
|
|
form = forms.ConfirmSubscription()
|
|
|
|
|
|
|
|
valid_address = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
address(config.PLATFORM_WALLET)
|
|
|
|
|
|
|
|
valid_address = True
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not config.PLATFORM_WALLET or valid_address is False:
|
|
|
|
|
|
|
|
await flash('Platform operator has not setup wallet yet. Try later.', 'warning')
|
|
|
|
|
|
|
|
return redirect(url_for('main.index'))
|
|
|
|
|
|
|
|
|
|
|
|
if UserRole.creator in current_user.roles:
|
|
|
|
if UserRole.creator in current_user.roles:
|
|
|
|
await flash('You already are a creator!', 'warning')
|
|
|
|
await flash('You already are a creator!', 'warning')
|
|
|
|
|
|
|
|
return redirect(url_for('main.index'))
|
|
|
|
if not config.PLATFORM_WALLET:
|
|
|
|
|
|
|
|
await flash('Platform operator has not setup wallet yet. Try later.', 'warning')
|
|
|
|
if form.validate_on_submit():
|
|
|
|
|
|
|
|
try:
|
|
|
|
return render_template(
|
|
|
|
data = {
|
|
|
|
'creator/join.html',
|
|
|
|
'txid': form.tx_id.data,
|
|
|
|
|
|
|
|
'tx_key': form.tx_key.data,
|
|
|
|
|
|
|
|
'address': config.PLATFORM_WALLET
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
res = make_wallet_rpc('check_tx_key', data)
|
|
|
|
|
|
|
|
existing_tx = Transaction.select().where(
|
|
|
|
|
|
|
|
Transaction.tx_id == form.tx_id.data.lower()
|
|
|
|
|
|
|
|
).first()
|
|
|
|
|
|
|
|
existing_sub = CreatorSubscription.select().where(
|
|
|
|
|
|
|
|
CreatorSubscription.tx == existing_tx
|
|
|
|
|
|
|
|
).first()
|
|
|
|
|
|
|
|
for i in ['confirmations', 'in_pool', 'received']:
|
|
|
|
|
|
|
|
assert i in res
|
|
|
|
|
|
|
|
if res['in_pool']:
|
|
|
|
|
|
|
|
await flash('That transaction is still in the mempool. You need to wait a few more minutes for it to clear. Try again in a bit.', 'warning')
|
|
|
|
|
|
|
|
elif res['received'] < to_atomic(config.CREATOR_SUBSCRIPTION_FEE_XMR):
|
|
|
|
|
|
|
|
await flash(f'Not enought XMR sent. {from_atomic(res["received"])} XMR sent, expected {config.CREATOR_SUBSCRIPTION_FEE_XMR} XMR.', 'error')
|
|
|
|
|
|
|
|
elif existing_tx:
|
|
|
|
|
|
|
|
if existing_sub:
|
|
|
|
|
|
|
|
await flash('This transaction was already used for another subscription.', 'warning')
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
await flash('Adding creator subscription.', 'success')
|
|
|
|
|
|
|
|
c = CreatorSubscription(
|
|
|
|
|
|
|
|
user=current_user,
|
|
|
|
|
|
|
|
tx=existing_tx,
|
|
|
|
|
|
|
|
atomic_xmr=res['received']
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
c.save()
|
|
|
|
|
|
|
|
current_user.roles.append(UserRole.creator)
|
|
|
|
|
|
|
|
current_user.save()
|
|
|
|
|
|
|
|
elif res['received'] >= to_atomic(config.CREATOR_SUBSCRIPTION_FEE_XMR):
|
|
|
|
|
|
|
|
await flash('Success! Welcome to the creator club!', 'success')
|
|
|
|
|
|
|
|
t = Transaction(
|
|
|
|
|
|
|
|
tx_id=form.tx_id.data.lower(),
|
|
|
|
|
|
|
|
atomic_xmr=res['received'],
|
|
|
|
|
|
|
|
to_address=config.PLATFORM_WALLET
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
t.save()
|
|
|
|
|
|
|
|
c = CreatorSubscription(
|
|
|
|
|
|
|
|
user=current_user,
|
|
|
|
|
|
|
|
tx=t,
|
|
|
|
|
|
|
|
atomic_xmr=res['received']
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
c.save()
|
|
|
|
|
|
|
|
current_user.roles.append(UserRole.creator)
|
|
|
|
|
|
|
|
current_user.save()
|
|
|
|
|
|
|
|
return redirect(url_for('creator.show', handle=current_user.handle))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
await flash('Something went wrong. No idea what, though. Check with admin.', 'error')
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
await flash(f'seems bad: {e}', 'error')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await render_template(
|
|
|
|
|
|
|
|
'creator/join.html',
|
|
|
|
new_fee_xmr=config.CREATOR_SUBSCRIPTION_FEE_XMR,
|
|
|
|
new_fee_xmr=config.CREATOR_SUBSCRIPTION_FEE_XMR,
|
|
|
|
form=form
|
|
|
|
form=form
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return redirect(url_for('main.index'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/creator/<handle>')
|
|
|
|
@bp.route('/creator/<handle>')
|
|
|
|
async def show(handle):
|
|
|
|
async def show(handle):
|
|
|
|
creator = User.select().where(User.handle == handle, User.roles.contains_any(UserRole.creator))
|
|
|
|
creator = User.select().where(
|
|
|
|
if creator:
|
|
|
|
User.handle == handle,
|
|
|
|
posts = Content.select().where(
|
|
|
|
User.roles.contains_any(UserRole.creator)
|
|
|
|
Content.creator == creator,
|
|
|
|
)
|
|
|
|
Content.hidden == False
|
|
|
|
if not creator:
|
|
|
|
).order_by(Content.post_date.desc())
|
|
|
|
|
|
|
|
return await render_template(
|
|
|
|
|
|
|
|
'creator/creator.html',
|
|
|
|
|
|
|
|
creator=creator,
|
|
|
|
|
|
|
|
posts=posts
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
await flash('That creator does not exist.')
|
|
|
|
await flash('That creator does not exist.')
|
|
|
|
return redirect(url_for('meta.index'))
|
|
|
|
return redirect(url_for('main.index'))
|
|
|
|
|
|
|
|
posts = Content.select().where(
|
|
|
|
|
|
|
|
Content.creator == creator,
|
|
|
|
|
|
|
|
Content.hidden == False
|
|
|
|
|
|
|
|
).order_by(Content.post_date.desc())
|
|
|
|
|
|
|
|
return await render_template(
|
|
|
|
|
|
|
|
'creator/show.html',
|
|
|
|
|
|
|
|
creator=creator,
|
|
|
|
|
|
|
|
posts=posts
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# @bp.route('/creator/<username>/subscription')
|
|
|
|
# @bp.route('/creator/<username>/subscription')
|
|
|
|
# async def subscription(username):
|
|
|
|
# async def subscription(username):
|
|
|
|