|
|
@ -1,4 +1,4 @@
|
|
|
|
import subprocess
|
|
|
|
from time import sleep
|
|
|
|
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
|
|
|
@ -9,6 +9,7 @@ from flask_login import login_required, current_user
|
|
|
|
from socket import socket
|
|
|
|
from socket import socket
|
|
|
|
from datetime import datetime
|
|
|
|
from datetime import datetime
|
|
|
|
from wowstash.blueprints.wallet import wallet_bp
|
|
|
|
from wowstash.blueprints.wallet import wallet_bp
|
|
|
|
|
|
|
|
from wowstash.library.docker import docker
|
|
|
|
from wowstash.library.jsonrpc import Wallet, to_atomic
|
|
|
|
from wowstash.library.jsonrpc import Wallet, to_atomic
|
|
|
|
from wowstash.library.cache import cache
|
|
|
|
from wowstash.library.cache import cache
|
|
|
|
from wowstash.forms import Send
|
|
|
|
from wowstash.forms import Send
|
|
|
@ -21,6 +22,7 @@ from wowstash import config
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
def loading():
|
|
|
|
def loading():
|
|
|
|
if current_user.wallet_connected and current_user.wallet_created:
|
|
|
|
if current_user.wallet_connected and current_user.wallet_created:
|
|
|
|
|
|
|
|
sleep(1)
|
|
|
|
return redirect(url_for('wallet.dashboard'))
|
|
|
|
return redirect(url_for('wallet.dashboard'))
|
|
|
|
return render_template('wallet/loading.html')
|
|
|
|
return render_template('wallet/loading.html')
|
|
|
|
|
|
|
|
|
|
|
@ -46,7 +48,7 @@ def dashboard():
|
|
|
|
for tx in transfers[type]:
|
|
|
|
for tx in transfers[type]:
|
|
|
|
all_transfers.append(tx)
|
|
|
|
all_transfers.append(tx)
|
|
|
|
balances = wallet.get_balances()
|
|
|
|
balances = wallet.get_balances()
|
|
|
|
qr_uri = f'wownero:{address}?tx_description="{current_user.email}"'
|
|
|
|
qr_uri = f'wownero:{address}?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(
|
|
|
@ -63,42 +65,33 @@ def dashboard():
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
def connect():
|
|
|
|
def connect():
|
|
|
|
if current_user.wallet_connected is False:
|
|
|
|
if current_user.wallet_connected is False:
|
|
|
|
tcp = socket()
|
|
|
|
wallet = docker.start_wallet(current_user.id)
|
|
|
|
tcp.bind(('', 0))
|
|
|
|
port = docker.get_port(wallet)
|
|
|
|
_, port = tcp.getsockname()
|
|
|
|
current_user.wallet_connected = docker.container_exists(wallet)
|
|
|
|
tcp.close()
|
|
|
|
|
|
|
|
command = f"""wownero-wallet-rpc \
|
|
|
|
|
|
|
|
--detach \
|
|
|
|
|
|
|
|
--non-interactive \
|
|
|
|
|
|
|
|
--rpc-bind-port {port} \
|
|
|
|
|
|
|
|
--wallet-file {config.WALLET_DIR}/{current_user.id}.wallet \
|
|
|
|
|
|
|
|
--rpc-login {current_user.id}:{current_user.wallet_password} \
|
|
|
|
|
|
|
|
--password {current_user.wallet_password} \
|
|
|
|
|
|
|
|
--daemon-address {config.DAEMON_PROTO}://{config.DAEMON_HOST}:{config.DAEMON_PORT} \
|
|
|
|
|
|
|
|
--daemon-login {config.DAEMON_USER}:{config.DAEMON_PASS} \
|
|
|
|
|
|
|
|
--log-file {config.WALLET_DIR}/{current_user.id}.log
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
proc = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
|
|
|
|
|
|
|
|
outs, errs = proc.communicate()
|
|
|
|
|
|
|
|
# print(outs)
|
|
|
|
|
|
|
|
if proc.returncode == 0:
|
|
|
|
|
|
|
|
print(f'Successfully started RPC for {current_user}!')
|
|
|
|
|
|
|
|
current_user.wallet_connected = True
|
|
|
|
|
|
|
|
current_user.wallet_port = port
|
|
|
|
current_user.wallet_port = port
|
|
|
|
current_user.wallet_pid = proc.pid
|
|
|
|
current_user.wallet_container = wallet
|
|
|
|
current_user.wallet_connect_date = datetime.now()
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
return "ok"
|
|
|
|
return 'ok'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@wallet_bp.route('/wallet/create')
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
|
|
|
def create():
|
|
|
|
|
|
|
|
if current_user.wallet_created is False:
|
|
|
|
|
|
|
|
docker.create_wallet(current_user.id)
|
|
|
|
|
|
|
|
current_user.wallet_created = True
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 'ok'
|
|
|
|
|
|
|
|
|
|
|
|
@wallet_bp.route('/wallet/status')
|
|
|
|
@wallet_bp.route('/wallet/status')
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
def status():
|
|
|
|
def status():
|
|
|
|
data = {
|
|
|
|
data = {
|
|
|
|
"created": current_user.wallet_created,
|
|
|
|
'created': current_user.wallet_created,
|
|
|
|
"connected": current_user.wallet_connected,
|
|
|
|
'connected': current_user.wallet_connected,
|
|
|
|
"port": current_user.wallet_port,
|
|
|
|
'port': current_user.wallet_port,
|
|
|
|
"date": current_user.wallet_connect_date
|
|
|
|
'container': current_user.wallet_container
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return jsonify(data)
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
|
|
|
|
|
|