setting up transfers
parent
215b9410c7
commit
5d15852607
@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source .venv/bin/activate
|
source .venv/bin/activate
|
||||||
export FLASK_APP=wowstash/run.py
|
export FLASK_APP=wowstash/app.py
|
||||||
export FLASK_SECRETS=config.py
|
export FLASK_SECRETS=config.py
|
||||||
export FLASK_DEBUG=1
|
export FLASK_DEBUG=1
|
||||||
flask eviscerate
|
flask $1
|
@ -1,38 +1,107 @@
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
from qrcode import make as qrcode_make
|
from qrcode import make as qrcode_make
|
||||||
from flask import request, render_template, session, redirect, url_for, current_app
|
from decimal import Decimal
|
||||||
|
from flask import request, render_template, session, redirect, url_for, current_app, flash
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
from wowstash.blueprints.wallet import wallet_bp
|
from wowstash.blueprints.wallet import wallet_bp
|
||||||
from wowstash.library.jsonrpc import wallet, daemon
|
from wowstash.library.jsonrpc import wallet, daemon
|
||||||
from wowstash.factory import login_manager
|
from wowstash.forms import Send
|
||||||
from wowstash.models import User
|
from wowstash.factory import login_manager, db
|
||||||
|
from wowstash.models import User, Transaction
|
||||||
|
|
||||||
|
|
||||||
@wallet_bp.route("/wallet/dashboard")
|
@wallet_bp.route("/wallet/dashboard")
|
||||||
@login_required
|
@login_required
|
||||||
def dashboard():
|
def dashboard():
|
||||||
all_transfers = list()
|
all_transfers = list()
|
||||||
|
send_form = Send()
|
||||||
_address_qr = BytesIO()
|
_address_qr = BytesIO()
|
||||||
user = User.query.get(current_user.id)
|
user = User.query.get(current_user.id)
|
||||||
wallet_height = wallet.height()['height']
|
wallet_height = wallet.height()['height']
|
||||||
daemon_height = daemon.height()['height']
|
|
||||||
subaddress = wallet.get_address(0, user.subaddress_index)
|
subaddress = wallet.get_address(0, user.subaddress_index)
|
||||||
balances = wallet.get_balance(0, user.subaddress_index)
|
balances = wallet.get_balance(0, user.subaddress_index)
|
||||||
transfers = wallet.get_transfers(0, user.subaddress_index)
|
transfers = wallet.get_transfers(0, user.subaddress_index)
|
||||||
|
txs_queued = Transaction.query.filter_by(from_user=user.id)
|
||||||
for type in transfers:
|
for type in transfers:
|
||||||
for tx in transfers[type]:
|
for tx in transfers[type]:
|
||||||
all_transfers.append(tx)
|
all_transfers.append(tx)
|
||||||
|
|
||||||
|
# data = {'account_index': account_index, 'address_indices': [subaddress_index]}
|
||||||
|
# _balance = self.make_rpc('get_balance', data)
|
||||||
|
# locked = from_atomic(_balance['per_subaddress'][0]['balance'])
|
||||||
|
# unlocked = from_atomic(_balance['per_subaddress'][0]['unlocked_balance'])
|
||||||
|
# return (float(locked), float(unlocked))
|
||||||
|
from wowstash.library.jsonrpc import from_atomic
|
||||||
|
from pprint import pprint
|
||||||
|
bal = wallet.make_rpc('get_balance', {'account_index': 0, 'address_indices': [user.subaddress_index]})
|
||||||
|
# print(from_atomic(bal))
|
||||||
|
pprint(bal)
|
||||||
|
# pprint(transfers)
|
||||||
|
# pprint(balances)
|
||||||
|
|
||||||
qr_uri = f'wownero:{subaddress}?tx_description="{current_user.email}"'
|
qr_uri = f'wownero:{subaddress}?tx_description="{current_user.email}"'
|
||||||
address_qr = qrcode_make(qr_uri).save(_address_qr)
|
address_qr = qrcode_make(qr_uri).save(_address_qr)
|
||||||
qrcode = b64encode(_address_qr.getvalue()).decode()
|
qrcode = b64encode(_address_qr.getvalue()).decode()
|
||||||
return render_template(
|
return render_template(
|
||||||
"wallet/dashboard.html",
|
"wallet/dashboard.html",
|
||||||
wallet_height=wallet_height,
|
wallet_height=wallet_height,
|
||||||
daemon_height=daemon_height,
|
|
||||||
subaddress=subaddress,
|
subaddress=subaddress,
|
||||||
balances=balances,
|
balances=balances,
|
||||||
all_transfers=all_transfers,
|
all_transfers=all_transfers,
|
||||||
qrcode=qrcode
|
qrcode=qrcode,
|
||||||
|
send_form=send_form,
|
||||||
|
txs_queued=txs_queued
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@wallet_bp.route("/wallet/send", methods=["GET", "POST"])
|
||||||
|
@login_required
|
||||||
|
def send():
|
||||||
|
send_form = Send()
|
||||||
|
redirect_url = url_for('wallet.dashboard') + "#send"
|
||||||
|
if send_form.validate_on_submit():
|
||||||
|
address = str(send_form.address.data)
|
||||||
|
|
||||||
|
# Check if Wownero wallet is available
|
||||||
|
if wallet.connected is False:
|
||||||
|
flash('Wallet RPC interface is unavailable at this time. Try again later.')
|
||||||
|
return redirect(redirect_url)
|
||||||
|
|
||||||
|
# Check if user funds flag is locked
|
||||||
|
if current_user.funds_locked:
|
||||||
|
flash('You currently have transactions pending and transfers are locked. Try again later.')
|
||||||
|
return redirect(redirect_url)
|
||||||
|
|
||||||
|
# Quick n dirty check to see if address is WOW
|
||||||
|
if len(address) not in [97, 108]:
|
||||||
|
flash('Invalid Wownero address provided.')
|
||||||
|
return redirect(redirect_url)
|
||||||
|
|
||||||
|
# Make sure the amount provided is a number
|
||||||
|
try:
|
||||||
|
amount = Decimal(send_form.amount.data)
|
||||||
|
except:
|
||||||
|
flash('Invalid Wownero amount specified.')
|
||||||
|
return redirect(redirect_url)
|
||||||
|
|
||||||
|
# Lock user funds
|
||||||
|
user = User.query.get(current_user.id)
|
||||||
|
user.funds_locked = True
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
# Queue the transaction
|
||||||
|
tx = Transaction(
|
||||||
|
from_user=user.id,
|
||||||
|
address=address,
|
||||||
|
amount=amount,
|
||||||
|
)
|
||||||
|
db.session.add(tx)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
# Redirect back
|
||||||
|
flash('Successfully queued transfer.')
|
||||||
|
return redirect(redirect_url)
|
||||||
|
else:
|
||||||
|
for field, errors in send_form.errors.items():
|
||||||
|
flash(f'{send_form[field].label}: {", ".join(errors)}')
|
||||||
|
return redirect(redirect_url)
|
||||||
|
@ -1,12 +1,23 @@
|
|||||||
|
from wowstash.library.jsonrpc import wallet
|
||||||
|
from wowstash.models import Transaction
|
||||||
|
from wowstash.factory import db
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(404)
|
# @app.errorhandler(404)
|
||||||
def not_found(error):
|
def not_found(error):
|
||||||
return make_response(jsonify({
|
return make_response(jsonify({
|
||||||
'error': 'Page not found'
|
'error': 'Page not found'
|
||||||
}), 404)
|
}), 404)
|
||||||
|
|
||||||
@app.cli.command('initdb')
|
# @app.cli.command('initdb')
|
||||||
def initdb():
|
def init_db():
|
||||||
from wowstash.models import *
|
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
|
# @app.cli.command('send_transfers')
|
||||||
|
def send_transfers():
|
||||||
|
txes = Transaction.query.all()
|
||||||
|
for i in txes:
|
||||||
|
print(i)
|
||||||
|
# tx = wallet.transfer(
|
||||||
|
# 0, current_user.subaddress_index, address, amount
|
||||||
|
# )
|
||||||
|
Loading…
Reference in New Issue