move qr to helper, add do limit checks, donation info

master
lza_menace 4 years ago
parent 4cf0cf87b2
commit e601bc1925

@ -1,3 +1,6 @@
from io import BytesIO
from base64 import b64encode
from qrcode import make as qrcode_make
from app.models import Operation from app.models import Operation
from app.library.digitalocean import do from app.library.digitalocean import do
from app.factory import db from app.factory import db
@ -11,6 +14,12 @@ def to_ausd(amount):
def from_ausd(amount): def from_ausd(amount):
return amount / 1000000 return amount / 1000000
def generate_qr(xmr_address, tx_description):
_address_qr = BytesIO()
qr_uri = f'monero:{xmr_address}?tx_description="{tx_description}"'
qrcode_make(qr_uri).save(_address_qr)
qrcode = b64encode(_address_qr.getvalue()).decode()
return qrcode
def cancel_operation(codename): def cancel_operation(codename):
op = Operation.query.filter( op = Operation.query.filter(

@ -24,6 +24,11 @@ class DigitalOcean(object):
r.raise_for_status() r.raise_for_status()
return r return r
# Account meta
def show_account(self):
r = self.make_req('get', 'account')
return r.json()['account']
# Domains and records # Domains and records
def create_record(self, name, ip_addr, type='A'): def create_record(self, name, ip_addr, type='A'):
data = { data = {

@ -1,5 +1,6 @@
from flask import Blueprint, render_template, request from flask import Blueprint, render_template, request
from app.models import Operation from app.models import Operation
from app.helpers import generate_qr
from app import config from app import config
@ -20,10 +21,14 @@ def index():
@bp.route('/info') @bp.route('/info')
def info(): def info():
qrcode = generate_qr(
config.PAYOUT_ADDRESS, "Donation to @lza_menace on xmrcannon.net"
)
return render_template( return render_template(
'info.html', 'info.html',
prices=Operation().get_pricing(), prices=Operation().get_pricing(),
config=config config=config,
qrcode=qrcode
) )

@ -1,10 +1,9 @@
from io import BytesIO
from base64 import b64encode
from qrcode import make as qrcode_make
from flask import Blueprint, render_template, request, redirect, url_for, flash from flask import Blueprint, render_template, request, redirect, url_for, flash
from app.library.monero import wallet from app.library.monero import wallet
from app.library.digitalocean import do
from app.library.cache import cache from app.library.cache import cache
from app.forms import CreateOperation from app.forms import CreateOperation
from app.helpers import generate_qr
from app.factory import db from app.factory import db
from app.models import Operation, Payout from app.models import Operation, Payout
from app import config from app import config
@ -18,10 +17,17 @@ def launchpad():
enabled = config.LAUNCHPAD_ENABLED == True enabled = config.LAUNCHPAD_ENABLED == True
if enabled is False: if enabled is False:
flash( flash(
'New launches have been disabled for the time being.' 'New launches have been disabled by the administrator for the time being.'
' Try again later!' ' Try again later!'
) )
return redirect(url_for('meta.index')) return redirect(url_for('meta.index'))
op_count = Operation.query.filter(
Operation.droplet_id > 0
).count()
op_limit = do.show_account()['droplet_limit']
if op_count >= op_limit:
flash('Maximum number of nodes in orbit already. Try again later!')
return redirect(url_for('meta.index'))
form = CreateOperation(request.form) form = CreateOperation(request.form)
if form.validate_on_submit(): if form.validate_on_submit():
op = Operation.query.filter( op = Operation.query.filter(
@ -48,10 +54,6 @@ def view_operation(id):
op = Operation.query.get(id) op = Operation.query.get(id)
if op: if op:
all_transfers = list() all_transfers = list()
_address_qr = BytesIO()
qr_uri = f'monero:{op.address}?tx_description={op.codename}'
qrcode_make(qr_uri).save(_address_qr)
qrcode = b64encode(_address_qr.getvalue()).decode()
txes = cache.get_transfers(op.account_idx) txes = cache.get_transfers(op.account_idx)
for type in txes: for type in txes:
for tx in txes[type]: for tx in txes[type]:
@ -60,6 +62,7 @@ def view_operation(id):
last_payout = Payout.query.filter( last_payout = Payout.query.filter(
Payout.operation_id == op.id Payout.operation_id == op.id
).order_by(Payout.create_date.desc()).first() ).order_by(Payout.create_date.desc()).first()
qrcode = generate_qr(op.address, f"Launching operation {op.id} on xmrcannon.net")
return render_template( return render_template(
'view_operation.html', 'view_operation.html',
op=op, op=op,

@ -21,7 +21,7 @@
<section class="hero is-light"> <section class="hero is-light">
<div class="hero-body"> <div class="hero-body">
<div class="container center"> <div class="container center">
<h1>Nodes in Orbit</h1> <h1>{{ funded_ops.count() }} Nodes in Orbit</h1>
<br /> <br />
{% if funded_ops %} {% if funded_ops %}
<table class="table center"> <table class="table center">

@ -25,13 +25,22 @@
<li>Prices are determined using the CoinGecko crypto market API.</li> <li>Prices are determined using the CoinGecko crypto market API.</li>
<li>If no more funds are left the node will be destroyed.</li> <li>If no more funds are left the node will be destroyed.</li>
<li>I will leave the operation available to refill for a few days.</li> <li>I will leave the operation available to refill for a few days.</li>
<li>You need to send at least ~{{ prices['minimum_xmr'] }} XMR to launch the node (this fluctuates).</li> <li>You need to send at least ~{{ prices['minimum_xmr'] | round(4) }} XMR to launch the node (this fluctuates).</li>
</ol> </ol>
<br /> <br />
<br /> <br />
<h1>Pricing Details</h1> <h1>Pricing Details</h1>
{% include 'includes/pricing_details.html' %} {% include 'includes/pricing_details.html' %}
<br />
<br />
<h1>Donation Info</h1>
<p>Donations will help me ramp up operations and scale out to more nodes since the pricing is mostly break-even (except for small maintenance fee).</p>
<p>XMR Address: {{ config.PAYOUT_ADDRESS }}</p>
<br />
<img src="data:image/png;base64,{{ qrcode }}" width=200 class="center">
</div> </div>
</div> </div>
</section> </section>

@ -67,7 +67,7 @@
<li>Prices are determined using the CoinGecko crypto market API.</li> <li>Prices are determined using the CoinGecko crypto market API.</li>
<li>If no more funds are left the node will be destroyed.</li> <li>If no more funds are left the node will be destroyed.</li>
<li>I will leave the operation available to refill for a few days.</li> <li>I will leave the operation available to refill for a few days.</li>
<li>You need to send at least {{ prices['minimum_xmr'] }} XMR to launch the node.</li> <li>You need to send at least {{ prices['minimum_xmr'] | round(4) }} XMR to launch the node. Send more, because this fluctuates.</li>
</ol> </ol>
<br /> <br />
{% include 'includes/pricing_details.html' %} {% include 'includes/pricing_details.html' %}

Loading…
Cancel
Save