Skip to content

Commit

Permalink
Updated GUI wallet to v0.1.0
Browse files Browse the repository at this point in the history
- Compatible with Sumokoin Akita (v0.4.1.0) binaries

Signed-off-by: Sumoshi Tanaka <[email protected]>
  • Loading branch information
sumoprojects committed Oct 3, 2018
1 parent 13ca62a commit ade47ad
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 88 deletions.
74 changes: 40 additions & 34 deletions app/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from __future__ import print_function

import os, binascii
import sys, os, binascii
from time import sleep
import uuid
import json
Expand Down Expand Up @@ -35,8 +35,12 @@

wallet_dir_path = os.path.join(DATA_DIR, 'wallets')
makeDir(wallet_dir_path)

wallet_log_dir_path = os.path.join(DATA_DIR, 'logs')
makeDir(wallet_log_dir_path)

password_regex = re.compile(r"^([a-zA-Z0-9!@#\$%\^&\*]{1,256})$")
wallet_file_regex = re.compile(r"wallet_(\d+)")

from webui import LogViewer

Expand Down Expand Up @@ -64,10 +68,9 @@ def import_wallet(self):
else:
return

new_wallet_file = os.path.join(wallet_dir_path, str(uuid.uuid4().hex) + '.bin')
new_wallet_file = os.path.join(wallet_dir_path, self.get_new_wallet_file_name())
if wallet_filename:
wallet_key_filename = wallet_filename + '.keys'
wallet_address_filename = wallet_filename + '.address.txt'

if not os.path.exists(wallet_key_filename):
QMessageBox.warning(self.new_wallet_ui, \
Expand All @@ -80,8 +83,6 @@ def import_wallet(self):
copy2(wallet_filename, os.path.join(wallet_dir_path, new_wallet_file))
copy2(wallet_key_filename, os.path.join(wallet_dir_path, \
new_wallet_file + '.keys'))
copy2(wallet_address_filename, os.path.join(wallet_dir_path, \
new_wallet_file + '.address.txt'))
except IOError, err:
self._detail_error_msg("Importing Wallet", "Error importing wallet!", str(err))
self.ui.reset_wallet()
Expand All @@ -107,10 +108,8 @@ def import_wallet(self):
self.on_new_wallet_show_progress_event.emit('Importing wallet...')
self.app_process_events()

wallet_address_filepath = new_wallet_file + ".address.txt"
wallet_address = readFile(wallet_address_filepath)
self.ui.wallet_info.wallet_filepath = new_wallet_file
self.ui.wallet_info.wallet_address = wallet_address
self.ui.wallet_info.wallet_address = "Sumo???"
self.ui.wallet_info.is_loaded =True
self.ui.wallet_info.save()
self.ui.run_wallet_rpc(wallet_password, 1)
Expand Down Expand Up @@ -205,61 +204,54 @@ def create_new_wallet(self, mnemonic_seed=u'', restore_height=0):

if has_password:
if not mnemonic_seed: # i.e. create new wallet
mnemonic_seed_language = "0" # english
mnemonic_seed_language = "1" # english
seed_language_list = [sl[1] for sl in seed_languages]
list_select_index = 0 if sys.platform in ['win32','cygwin','win64'] else 1
lang, ok = QInputDialog.getItem(self.new_wallet_ui, "Mnemonic Seed Language",
"Select a language for wallet mnemonic seed:",
seed_language_list, 0, False)
seed_language_list, list_select_index, False)
if ok and lang:
for sl in seed_languages:
if sl[1] == lang:
mnemonic_seed_language = sl[0]
break
else:
QMessageBox.warning(self.new_wallet_ui, \
'Mnemonic Seed Language',\
"No language is selected!\
<br>'English' will be used for mnemonic seed")
return

self.on_new_wallet_show_progress_event.emit("Restoring wallet..." \
if mnemonic_seed else "Creating wallet...")
self.app_process_events()
wallet_filepath = os.path.join(wallet_dir_path, str(uuid.uuid4().hex) + '.bin')
wallet_log_path = os.path.join(wallet_dir_path, 'sumo-wallet-cli.log')
wallet_filepath = os.path.join(wallet_dir_path, self.get_new_wallet_file_name())
wallet_log_path = os.path.join(wallet_log_dir_path, 'sumo-wallet-cli-bin.log')
resources_path = self.app.property("ResPath")
if not mnemonic_seed: # i.e. create new wallet
self.wallet_cli_manager = WalletCliManager(resources_path, \
wallet_filepath, wallet_log_path)
self.wallet_cli_manager.start()
self.app_process_events(1)
self.app_process_events(0.1)
self.wallet_cli_manager.send_command(wallet_password)
self.app_process_events(0.5)
self.app_process_events(0.1)
self.wallet_cli_manager.send_command(mnemonic_seed_language)
# self.app_process_events(0.5)
# self.wallet_cli_manager.send_command("exit")
else: # restore wallet
self.wallet_cli_manager = WalletCliManager(resources_path, \
wallet_filepath, wallet_log_path, True, restore_height)
self.wallet_cli_manager.start()
self.app_process_events(1)
self.wallet_cli_manager.send_command(wallet_filepath)
self.app_process_events(0.5)
self.wallet_cli_manager.send_command("Y")
self.app_process_events(0.5)
self.app_process_events(0.1)
self.wallet_cli_manager.send_command(mnemonic_seed)
if restore_height == 0:
self.app_process_events(0.5)
self.wallet_cli_manager.send_command("0")
self.app_process_events(0.5)
self.app_process_events(0.1)
self.wallet_cli_manager.send_command("")
self.app_process_events(0.1)
self.wallet_cli_manager.send_command(wallet_password)
self.app_process_events(0.5)
self.app_process_events(0.1)
self.wallet_cli_manager.send_command(wallet_password)
counter = 0
while not self.wallet_cli_manager.is_ready():
self.app_process_events(1)
counter += 1
if counter > 10:
break
self.app_process_events(1)
self.wallet_cli_manager.send_command("save")
self.wallet_cli_manager.stop()
except Exception, err:
log(str(err), LEVEL_ERROR)
Expand All @@ -279,15 +271,15 @@ def create_new_wallet(self, mnemonic_seed=u'', restore_height=0):
break

if self._is_wallet_files_existed(wallet_filepath):
wallet_address = readFile(wallet_filepath + ".address.txt")
wallet_address = ""
self.ui.wallet_info.wallet_filepath = wallet_filepath
self.ui.wallet_info.wallet_password = hashlib.sha256(wallet_password).hexdigest()
self.ui.wallet_info.wallet_address = wallet_address
self.ui.wallet_info.is_loaded = True

self.ui.wallet_info.save()

self.ui.run_wallet_rpc(wallet_password, 1)
self.ui.run_wallet_rpc(wallet_password, 2)
counter = 0
block_height = 0

Expand All @@ -314,6 +306,7 @@ def create_new_wallet(self, mnemonic_seed=u'', restore_height=0):
self.ui.reset_wallet(delete_files=False)
return

self.ui.wallet_rpc_manager.rpc_request.save_wallet_to_file()
self._show_wallet_info()
self.ui.wallet_info.save()
else:
Expand All @@ -324,7 +317,16 @@ def create_new_wallet(self, mnemonic_seed=u'', restore_height=0):

def _is_wallet_files_existed(self, wallet_filepath):
return os.path.exists(wallet_filepath) and os.path.exists(wallet_filepath + ".keys")


def get_new_wallet_file_name(self):
wallet_files = os.listdir(wallet_dir_path)
wallet_file_numbers = [0]
for wf in wallet_files:
m_file_num = wallet_file_regex.search(wf)
if m_file_num:
wallet_file_numbers.append(int(m_file_num.group(1)))
return "wallet_%d.bin" % (max(wallet_file_numbers) + 1)

@Slot()
def rescan_spent(self):
self.app_process_events()
Expand Down Expand Up @@ -736,7 +738,11 @@ def _custom_input_dialog(self, ui, title, label,
def _show_wallet_info(self):
wallet_rpc_request = self.ui.wallet_rpc_manager.rpc_request
wallet_info = {}
wallet_info['address'] = self.ui.wallet_info.wallet_address
address_obj = wallet_rpc_request.get_address()
if 'address' in address_obj:
wallet_info['address'] = address_obj['address']
else:
wallet_info['address'] = "Sumo???"
wallet_info['seed'] = wallet_rpc_request.query_key(key_type="mnemonic")
wallet_info['view_key'] = wallet_rpc_request.query_key(key_type="view_key")
balance, unlocked_balance, _ = wallet_rpc_request.get_balance()
Expand Down
2 changes: 1 addition & 1 deletion classes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class AppSettings():
default_settings = {
"daemon": {
"log_level": 0,
"block_sync_size": 10,
"block_sync_size": 20,
"limit_rate_up": 2048,
"limit_rate_down": 8192,
},
Expand Down
11 changes: 6 additions & 5 deletions html/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
Main UI html
'''

html ="""
html =u"""
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="./css/bootstrap.min.css" rel="stylesheet">
<link href="./css/font-awesome.min.css" rel="stylesheet">
<style type="text/css">
Expand Down Expand Up @@ -1397,14 +1398,14 @@
<div class="col-xs-12">
<div class="radio">
<label>
<input type="radio" name="daemon_block_sync_size" id="block_sync_size_10" value="10" onclick="set_block_sync_size(10)" checked="">
10 (default, for slow network)
<input type="radio" name="daemon_block_sync_size" id="block_sync_size_10" value="10" onclick="set_block_sync_size(10)">
10 (for slow network)
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="daemon_block_sync_size" id="block_sync_size_20" value="20" onclick="set_block_sync_size(20)">
20 (for normal network)
<input type="radio" name="daemon_block_sync_size" id="block_sync_size_20" value="20" onclick="set_block_sync_size(20)" checked="">
20 (default, for normal network)
</label>
</div>
<div class="radio">
Expand Down
10 changes: 5 additions & 5 deletions html/newwallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,15 @@
<label for="wallet_address">Address</label>
<input id="wallet_address" type="text" class="form-control address-box" style="color:#c7254e;" readonly="readonly" value="Sumoo..."/>
</div>
<div class="form-group">
<label for="wallet_seed_words">Mnemonic seed <code style="font-weight: bold; color: red">(Important! Always backup the seed words for wallet recovery!)</code></label>
<button id="copy_seed_btn" type="button" class="btn btn-warning btn-sm" style="text-transform: none" onclick="copy_seed()"><i class="fa fa-copy"></i> Copy Seed Words</button>
<textarea id="wallet_seed_words" class="form-control address-box" style="height:70px;font-size:95%;color:#333" readonly="readonly"></textarea>
</div>
<div class="form-group">
<label for="wallet_viewkey">View key (private)</label>
<input id="wallet_viewkey" class="form-control address-box" type="text" readonly="readonly" />
</div>
<div class="form-group">
<label for="wallet_seed_words">Mnemonic seed <code style="font-weight: bold; color: red">(NOTICE: Always backup the seed words for wallet recovery!)</code></label>
<button id="copy_seed_btn" type="button" class="btn btn-warning btn-sm" style="text-transform: none" onclick="copy_seed()"><i class="fa fa-copy"></i> Copy Seed Words</button>
<textarea id="wallet_seed_words" class="form-control address-box" style="height:70px;font-size:95%;color:#333" readonly="readonly"></textarea>
</div>
<div class="form-group">
<h5><i>Balance:</i> <span id="balance">0.000000000</span></h5>
<h5><i>Unlocked Balance:</i> <span id="unlocked_balance">0.000000000</span></h5>
Expand Down
32 changes: 15 additions & 17 deletions manager/ProcessManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sys, os
import re
from subprocess import Popen, PIPE, STDOUT
import signal
from threading import Thread
from multiprocessing import Process, Event
from time import sleep
Expand Down Expand Up @@ -55,8 +56,8 @@ def stop(self):
counter = 0
while True:
if self.is_proc_running():
if counter < 10:
if counter == 2:
if counter < 30:
if counter == 10:
try:
self.send_command('exit')
except:
Expand All @@ -79,19 +80,15 @@ def is_proc_running(self):


class SumokoindManager(ProcessManager):
def __init__(self, resources_path, log_level=0, block_sync_size=10, limit_rate_up=2048, limit_rate_down=8192):
def __init__(self, resources_path, log_level=0, block_sync_size=20, limit_rate_up=2048, limit_rate_down=8192):
proc_args = u'%s/bin/sumokoind --log-level %d --block-sync-size %d --limit-rate-up %d --limit-rate-down %d' % (resources_path, log_level, block_sync_size, limit_rate_up, limit_rate_down)
ProcessManager.__init__(self, proc_args, "sumokoind")
self.synced = Event()
self.stopped = Event()

def run(self):
# synced_str = "You are now synchronized with the network"
err_str = "ERROR"
for line in iter(self.proc.stdout.readline, b''):
# if not self.synced.is_set() and line.startswith(synced_str):
# self.synced.set()
# log(synced_str, LEVEL_INFO, self.proc_name)
if err_str in line:
self.last_error = line.rstrip()
log("[%s]>>> %s" % (self.proc_name, line.rstrip()), LEVEL_ERROR, self.proc_name)
Expand All @@ -106,13 +103,13 @@ def run(self):
class WalletCliManager(ProcessManager):
fail_to_connect_str = "wallet failed to connect to daemon"

def __init__(self, resources_path, wallet_file_path, wallet_log_path, restore_wallet=False, restore_height=0):
def __init__(self, resources_path, wallet_file_path, wallet_log_dir_path, restore_wallet=False, restore_height=0):
if not restore_wallet:
wallet_args = u'%s/bin/sumo-wallet-cli --generate-new-wallet=%s --log-file=%s' \
% (resources_path, wallet_file_path, wallet_log_path)
% (resources_path, wallet_file_path, wallet_log_dir_path)
else:
wallet_args = u'%s/bin/sumo-wallet-cli --log-file=%s --restore-deterministic-wallet --restore-height %d' \
% (resources_path, wallet_log_path, restore_height)
wallet_args = u'%s/bin/sumo-wallet-cli --restore-deterministic-wallet --restore-height %d --generate-new-wallet=%s --log-file=%s --daemon-port 99999' \
% (resources_path, restore_height, wallet_file_path, wallet_log_dir_path)
ProcessManager.__init__(self, wallet_args, "sumo-wallet-cli")
self._ready = Event()
self.last_error = ""
Expand Down Expand Up @@ -159,16 +156,17 @@ def is_connected(self):

class WalletRPCManager(ProcessManager):
def __init__(self, resources_path, wallet_file_path, wallet_password, app, log_level=1):
self.user_agent = str(uuid4().hex)
wallet_log_path = os.path.join(os.path.dirname(wallet_file_path), "sumo-wallet-rpc.log")
wallet_rpc_args = u'%s/bin/sumo-wallet-rpc --wallet-file %s --log-file %s --rpc-bind-port 19736 --user-agent %s --log-level %d' \
% (resources_path, wallet_file_path, wallet_log_path, self.user_agent, log_level)
self.rpc_user_name = str(uuid4().hex)[:12]
self.rpc_password = str(uuid4().hex)[:12]
wallet_log_dir_path = os.path.join(os.path.dirname(wallet_file_path), ".." , "logs", "sumo-wallet-rpc-bin.log")
wallet_rpc_args = u'%s/bin/sumo-wallet-rpc --wallet-file %s --log-file %s --rpc-bind-port 19738 --rpc-login %s:%s --prompt-for-password --log-level %d' \
% (resources_path, wallet_file_path, wallet_log_dir_path, self.rpc_user_name, self.rpc_password, log_level)

ProcessManager.__init__(self, wallet_rpc_args, "sumo-wallet-rpc")
sleep(0.2)
self.send_command(wallet_password)

self.rpc_request = WalletRPCRequest(app, self.user_agent)
self.rpc_request = WalletRPCRequest(app, self.rpc_user_name, self.rpc_password)
# self.rpc_request.start()
self._ready = Event()
self.block_height = 0
Expand Down Expand Up @@ -236,6 +234,6 @@ def stop(self):
break
else:
break
self._ready = False
self._ready = Event()
log("[%s] stopped" % self.proc_name, LEVEL_INFO, self.proc_name)

Loading

0 comments on commit ade47ad

Please sign in to comment.