refactor container start process, setup wallet secrets

mm-logging
lza_menace 4 years ago
parent d018d375bc
commit bb6997e7a4

@ -39,6 +39,10 @@ def dashboard():
username=current_user.id, username=current_user.id,
password=current_user.wallet_password password=current_user.wallet_password
) )
if not docker.container_exists(current_user.wallet_container):
current_user.clear_wallet_data()
return redirect(url_for('wallet.loading'))
if not wallet.connected: if not wallet.connected:
return redirect(url_for('wallet.loading')) return redirect(url_for('wallet.loading'))
@ -51,6 +55,9 @@ def dashboard():
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()
seed = wallet.seed()
spend_key = wallet.spend_key()
view_key = wallet.view_key()
return render_template( return render_template(
'wallet/dashboard.html', 'wallet/dashboard.html',
transfers=all_transfers, transfers=all_transfers,
@ -58,7 +65,10 @@ def dashboard():
address=address, address=address,
qrcode=qrcode, qrcode=qrcode,
send_form=send_form, send_form=send_form,
user=current_user user=current_user,
seed=seed,
spend_key=spend_key,
view_key=view_key,
) )
@wallet_bp.route('/wallet/connect') @wallet_bp.route('/wallet/connect')

@ -1,5 +1,5 @@
from docker import from_env, APIClient from docker import from_env, APIClient
from docker.errors import NotFound from docker.errors import NotFound, NullResource, APIError
from socket import socket from socket import socket
from wowstash import config from wowstash import config
from wowstash.models import User from wowstash.models import User
@ -42,6 +42,7 @@ class Docker(object):
def start_wallet(self, user_id): def start_wallet(self, user_id):
u = User.query.get(user_id) u = User.query.get(user_id)
container_name = f'start_wallet_{u.id}'
command = f"""wownero-wallet-rpc \ command = f"""wownero-wallet-rpc \
--non-interactive \ --non-interactive \
--rpc-bind-port {self.listen_port} \ --rpc-bind-port {self.listen_port} \
@ -54,24 +55,29 @@ class Docker(object):
--daemon-login {config.DAEMON_USER}:{config.DAEMON_PASS} \ --daemon-login {config.DAEMON_USER}:{config.DAEMON_PASS} \
--log-file /wallet/{u.id}-rpc.log --log-file /wallet/{u.id}-rpc.log
""" """
container = self.client.containers.run( try:
self.wownero_image, container = self.client.containers.run(
command=command, self.wownero_image,
auto_remove=True, command=command,
name=f'start_wallet_{u.id}', auto_remove=True,
remove=True, name=container_name,
detach=True, remove=True,
ports={ detach=True,
f'{self.listen_port}/tcp': ('127.0.0.1', None) ports={
}, f'{self.listen_port}/tcp': ('127.0.0.1', None)
volumes={ },
f'{self.wallet_dir}/{u.id}': { volumes={
'bind': '/wallet', f'{self.wallet_dir}/{u.id}': {
'mode': 'rw' 'bind': '/wallet',
'mode': 'rw'
}
} }
} )
) return container.short_id
return container.short_id except APIError as e:
if str(e).startswith('409'):
container = self.client.containers.get(container_name)
return container.short_id
def get_port(self, container_id): def get_port(self, container_id):
client = APIClient() client = APIClient()
@ -85,6 +91,8 @@ class Docker(object):
return True return True
except NotFound: except NotFound:
return False return False
except NullResource:
return False
def stop_container(self, container_id): def stop_container(self, container_id):
if self.container_exists(container_id): if self.container_exists(container_id):

@ -49,6 +49,15 @@ class Wallet(JSONRPC):
def height(self): def height(self):
return self.make_rpc('get_height', {}) return self.make_rpc('get_height', {})
def spend_key(self):
return self.make_rpc('query_key', {'key_type': 'spend_key'})['key']
def view_key(self):
return self.make_rpc('query_key', {'key_type': 'view_key'})['key']
def seed(self):
return self.make_rpc('query_key', {'key_type': 'mnemonic'})['key']
def new_address(self, account_index=0, label=None): def new_address(self, account_index=0, label=None):
data = {'account_index': account_index, 'label': label} data = {'account_index': account_index, 'label': label}
_address = self.make_rpc('create_address', data) _address = self.make_rpc('create_address', data)

@ -20,10 +20,13 @@
<p class="inline">{{ balances[1] | from_atomic }} WOW ({{ balances[0] | from_atomic }} locked)</p> <p class="inline">{{ balances[1] | from_atomic }} WOW ({{ balances[0] | from_atomic }} locked)</p>
<span class="dashboard-buttons"> <span class="dashboard-buttons">
<div class="col-sm-6 dashboard-button"> <div class="col-sm-6 dashboard-button">
<a class="btn btn-lg btn-link btn-outline btn-xl js-scroll-trigger" href="#transfers">List</a> <a class="btn btn-lg btn-link btn-outline btn-xl js-scroll-trigger" href="#transfers">See Txes</a>
</div> </div>
<div class="col-sm-6 dashboard-button"> <div class="col-sm-6 dashboard-button">
<a class="btn btn-lg btn-link btn-outline btn-xl js-scroll-trigger" href="#send">Send</a> <a class="btn btn-lg btn-link btn-outline btn-xl js-scroll-trigger" href="#send">Send Tx</a>
</div>
<div class="col-sm-6 dashboard-button">
<a class="btn btn-lg btn-link btn-outline btn-xl js-scroll-trigger" href="#secrets">See Secrets</a>
</div> </div>
</span> </span>
</div> </div>
@ -96,6 +99,24 @@
</div> </div>
</section> </section>
<section class="section1" id="secrets">
<div class="container">
<div class="section-heading text-center">
<h2>Secrets</h2>
<p>You need to save the secrets below; write them down on a physical medium and keep it in a safe location. These can be used to restore your funds to another device in the future.</p>
<hr><br>
<h3>Mnemonic Seed</h3>
<p class="small">{{ seed }}</p>
<br>
<h3>Spend Key</h3>
<p class="small">{{ spend_key }}</p>
<br>
<h3>View Key</h3>
<p class="small">{{ view_key }}</p>
</div>
</div>
</section>
{% include 'footer.html' %} {% include 'footer.html' %}
{% include 'scripts.html' %} {% include 'scripts.html' %}