wizard/wallet: clean up imports, code style warnings.
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
|
||||||
import json
|
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
@@ -17,7 +15,7 @@ from electrum.i18n import _
|
|||||||
from electrum.keystore import bip44_derivation, bip39_to_seed, purpose48_derivation, ScriptTypeNotSupported
|
from electrum.keystore import bip44_derivation, bip39_to_seed, purpose48_derivation, ScriptTypeNotSupported
|
||||||
from electrum.plugin import run_hook, HardwarePluginLibraryUnavailable
|
from electrum.plugin import run_hook, HardwarePluginLibraryUnavailable
|
||||||
from electrum.storage import StorageReadWriteError
|
from electrum.storage import StorageReadWriteError
|
||||||
from electrum.util import WalletFileException, get_new_wallet_name, UserCancelled, UserFacingException, InvalidPassword
|
from electrum.util import WalletFileException, get_new_wallet_name, UserFacingException, InvalidPassword
|
||||||
from electrum.wallet import wallet_types
|
from electrum.wallet import wallet_types
|
||||||
from .wizard import QEAbstractWizard, WizardComponent
|
from .wizard import QEAbstractWizard, WizardComponent
|
||||||
from electrum.logging import get_logger, Logger
|
from electrum.logging import get_logger, Logger
|
||||||
@@ -60,27 +58,28 @@ class QENewWalletWizard(NewWalletWizard, QEAbstractWizard, MessageBoxMixin):
|
|||||||
self.setWindowTitle(_('Create/Restore wallet'))
|
self.setWindowTitle(_('Create/Restore wallet'))
|
||||||
|
|
||||||
self._path = path
|
self._path = path
|
||||||
|
self._password = None
|
||||||
|
|
||||||
# attach gui classes to views
|
# attach gui classes to views
|
||||||
self.navmap_merge({
|
self.navmap_merge({
|
||||||
'wallet_name': { 'gui': WCWalletName },
|
'wallet_name': {'gui': WCWalletName},
|
||||||
'wallet_type': { 'gui': WCWalletType },
|
'wallet_type': {'gui': WCWalletType},
|
||||||
'keystore_type': { 'gui': WCKeystoreType },
|
'keystore_type': {'gui': WCKeystoreType},
|
||||||
'create_seed': { 'gui': WCCreateSeed },
|
'create_seed': {'gui': WCCreateSeed},
|
||||||
'confirm_seed': { 'gui': WCConfirmSeed },
|
'confirm_seed': {'gui': WCConfirmSeed},
|
||||||
'have_seed': { 'gui': WCHaveSeed },
|
'have_seed': {'gui': WCHaveSeed},
|
||||||
'choose_hardware_device': { 'gui': WCChooseHWDevice },
|
'choose_hardware_device': {'gui': WCChooseHWDevice},
|
||||||
'script_and_derivation': { 'gui': WCScriptAndDerivation},
|
'script_and_derivation': {'gui': WCScriptAndDerivation},
|
||||||
'have_master_key': { 'gui': WCHaveMasterKey },
|
'have_master_key': {'gui': WCHaveMasterKey},
|
||||||
'multisig': { 'gui': WCMultisig },
|
'multisig': {'gui': WCMultisig},
|
||||||
'multisig_cosigner_keystore': { 'gui': WCCosignerKeystore },
|
'multisig_cosigner_keystore': {'gui': WCCosignerKeystore},
|
||||||
'multisig_cosigner_key': { 'gui': WCHaveMasterKey },
|
'multisig_cosigner_key': {'gui': WCHaveMasterKey},
|
||||||
'multisig_cosigner_seed': { 'gui': WCHaveSeed },
|
'multisig_cosigner_seed': {'gui': WCHaveSeed},
|
||||||
'multisig_cosigner_hardware': { 'gui': WCChooseHWDevice },
|
'multisig_cosigner_hardware': {'gui': WCChooseHWDevice},
|
||||||
'multisig_cosigner_script_and_derivation': { 'gui': WCScriptAndDerivation},
|
'multisig_cosigner_script_and_derivation': {'gui': WCScriptAndDerivation},
|
||||||
'imported': { 'gui': WCImport },
|
'imported': {'gui': WCImport},
|
||||||
'wallet_password': { 'gui': WCWalletPassword },
|
'wallet_password': {'gui': WCWalletPassword},
|
||||||
'wallet_password_hardware': { 'gui': WCWalletPasswordHardware }
|
'wallet_password_hardware': {'gui': WCWalletPasswordHardware}
|
||||||
})
|
})
|
||||||
|
|
||||||
# add open existing wallet from wizard, incl hw unlock
|
# add open existing wallet from wizard, incl hw unlock
|
||||||
@@ -137,7 +136,6 @@ class QENewWalletWizard(NewWalletWizard, QEAbstractWizard, MessageBoxMixin):
|
|||||||
|
|
||||||
run_hook('init_wallet_wizard', self)
|
run_hook('init_wallet_wizard', self)
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def path(self):
|
def path(self):
|
||||||
return self._path
|
return self._path
|
||||||
@@ -211,10 +209,10 @@ class QENewWalletWizard(NewWalletWizard, QEAbstractWizard, MessageBoxMixin):
|
|||||||
|
|
||||||
exc = None
|
exc = None
|
||||||
|
|
||||||
def task_wrap(task):
|
def task_wrap(_task):
|
||||||
nonlocal exc
|
nonlocal exc
|
||||||
try:
|
try:
|
||||||
task()
|
_task()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
exc = e
|
exc = e
|
||||||
|
|
||||||
@@ -303,9 +301,9 @@ class WCWalletName(WizardComponent, Logger):
|
|||||||
wallet_folder = os.path.dirname(path)
|
wallet_folder = os.path.dirname(path)
|
||||||
|
|
||||||
def on_choose():
|
def on_choose():
|
||||||
path, __ = QFileDialog.getOpenFileName(self, "Select your wallet file", wallet_folder)
|
_path, __ = QFileDialog.getOpenFileName(self, "Select your wallet file", wallet_folder)
|
||||||
if path:
|
if _path:
|
||||||
self.name_e.setText(path)
|
self.name_e.setText(_path)
|
||||||
|
|
||||||
def on_filename(filename):
|
def on_filename(filename):
|
||||||
# FIXME? "filename" might contain ".." (etc) and hence sketchy path traversals are possible
|
# FIXME? "filename" might contain ".." (etc) and hence sketchy path traversals are possible
|
||||||
@@ -316,14 +314,14 @@ class WCWalletName(WizardComponent, Logger):
|
|||||||
self.wallet_is_open = False
|
self.wallet_is_open = False
|
||||||
self.wallet_needs_hw_unlock = False
|
self.wallet_needs_hw_unlock = False
|
||||||
if filename:
|
if filename:
|
||||||
path = os.path.join(wallet_folder, filename)
|
_path = os.path.join(wallet_folder, filename)
|
||||||
wallet_from_memory = self.wizard._daemon.get_wallet(path)
|
wallet_from_memory = self.wizard._daemon.get_wallet(_path)
|
||||||
try:
|
try:
|
||||||
if wallet_from_memory:
|
if wallet_from_memory:
|
||||||
temp_storage = wallet_from_memory.storage # type: Optional[WalletStorage]
|
temp_storage = wallet_from_memory.storage # type: Optional[WalletStorage]
|
||||||
self.wallet_is_open = True
|
self.wallet_is_open = True
|
||||||
else:
|
else:
|
||||||
temp_storage = WalletStorage(path)
|
temp_storage = WalletStorage(_path)
|
||||||
self.wallet_exists = temp_storage.file_exists()
|
self.wallet_exists = temp_storage.file_exists()
|
||||||
except (StorageReadWriteError, WalletFileException) as e:
|
except (StorageReadWriteError, WalletFileException) as e:
|
||||||
msg = _('Cannot read file') + f'\n{repr(e)}'
|
msg = _('Cannot read file') + f'\n{repr(e)}'
|
||||||
@@ -578,6 +576,8 @@ class WCHaveSeed(WizardComponent, Logger):
|
|||||||
WizardComponent.__init__(self, parent, wizard, title=_('Enter Seed'))
|
WizardComponent.__init__(self, parent, wizard, title=_('Enter Seed'))
|
||||||
Logger.__init__(self)
|
Logger.__init__(self)
|
||||||
|
|
||||||
|
self.slayout = None
|
||||||
|
|
||||||
self.layout().addWidget(WWLabel(_('Please enter your seed phrase in order to restore your wallet.')))
|
self.layout().addWidget(WWLabel(_('Please enter your seed phrase in order to restore your wallet.')))
|
||||||
|
|
||||||
# TODO: SeedLayout assumes too much in parent, refactor SeedLayout
|
# TODO: SeedLayout assumes too much in parent, refactor SeedLayout
|
||||||
@@ -650,6 +650,9 @@ class WCScriptAndDerivation(WizardComponent, Logger):
|
|||||||
WizardComponent.__init__(self, parent, wizard, title=_('Script type and Derivation path'))
|
WizardComponent.__init__(self, parent, wizard, title=_('Script type and Derivation path'))
|
||||||
Logger.__init__(self)
|
Logger.__init__(self)
|
||||||
|
|
||||||
|
self.choice_w = None
|
||||||
|
self.derivation_path_edit = None
|
||||||
|
|
||||||
def on_ready(self):
|
def on_ready(self):
|
||||||
message1 = _('Choose the type of addresses in your wallet.')
|
message1 = _('Choose the type of addresses in your wallet.')
|
||||||
message2 = ' '.join([
|
message2 = ' '.join([
|
||||||
@@ -797,6 +800,8 @@ class WCHaveMasterKey(WizardComponent):
|
|||||||
def __init__(self, parent, wizard):
|
def __init__(self, parent, wizard):
|
||||||
WizardComponent.__init__(self, parent, wizard, title=_('Create keystore from a master key'))
|
WizardComponent.__init__(self, parent, wizard, title=_('Create keystore from a master key'))
|
||||||
|
|
||||||
|
self.slayout = None
|
||||||
|
|
||||||
self.message_create = ' '.join([
|
self.message_create = ' '.join([
|
||||||
_("To create a watching-only wallet, please enter your master public key (xpub/ypub/zpub)."),
|
_("To create a watching-only wallet, please enter your master public key (xpub/ypub/zpub)."),
|
||||||
_("To create a spending wallet, please enter a master private key (xprv/yprv/zprv).")
|
_("To create a spending wallet, please enter a master private key (xprv/yprv/zprv).")
|
||||||
@@ -816,26 +821,24 @@ class WCHaveMasterKey(WizardComponent):
|
|||||||
class Hack:
|
class Hack:
|
||||||
def setEnabled(self2, b):
|
def setEnabled(self2, b):
|
||||||
self.valid = b
|
self.valid = b
|
||||||
|
|
||||||
def setToolTip(self2, b):
|
def setToolTip(self2, b):
|
||||||
pass
|
pass
|
||||||
self.next_button = Hack()
|
self.next_button = Hack()
|
||||||
|
|
||||||
def on_ready(self):
|
def on_ready(self):
|
||||||
# if self.wallet_type == 'standard':
|
|
||||||
# v = keystore.is_master_key
|
|
||||||
# self.add_xpub_dialog(title=title, message=message, run_next=self.on_restore_from_key, is_valid=v)
|
|
||||||
# else:
|
|
||||||
# i = len(self.keystores) + 1
|
|
||||||
# self.add_cosigner_dialog(index=i, run_next=self.on_restore_from_key, is_valid=keystore.is_bip32_key)
|
|
||||||
if self.wizard_data['wallet_type'] == 'standard':
|
if self.wizard_data['wallet_type'] == 'standard':
|
||||||
self.label.setText(self.message_create)
|
self.label.setText(self.message_create)
|
||||||
is_valid = lambda x: bool(keystore.from_master_key(x))
|
|
||||||
|
def is_valid(x) -> bool:
|
||||||
|
return bool(keystore.from_master_key(x))
|
||||||
elif self.wizard_data['wallet_type'] == 'multisig':
|
elif self.wizard_data['wallet_type'] == 'multisig':
|
||||||
if 'multisig_current_cosigner' in self.wizard_data:
|
if 'multisig_current_cosigner' in self.wizard_data:
|
||||||
self.title = _("Add Cosigner {}").format(self.wizard_data['multisig_current_cosigner'])
|
self.title = _("Add Cosigner {}").format(self.wizard_data['multisig_current_cosigner'])
|
||||||
self.label.setText(self.message_cosign)
|
self.label.setText(self.message_cosign)
|
||||||
else:
|
else:
|
||||||
self.label.setText(self.message_create)
|
self.label.setText(self.message_create)
|
||||||
|
|
||||||
def is_valid(x) -> bool:
|
def is_valid(x) -> bool:
|
||||||
if not keystore.is_bip32_key(x):
|
if not keystore.is_bip32_key(x):
|
||||||
return False
|
return False
|
||||||
@@ -933,12 +936,15 @@ class WCImport(WizardComponent):
|
|||||||
class Hack:
|
class Hack:
|
||||||
def setEnabled(self2, b):
|
def setEnabled(self2, b):
|
||||||
self.valid = b
|
self.valid = b
|
||||||
|
|
||||||
def setToolTip(self2, b):
|
def setToolTip(self2, b):
|
||||||
pass
|
pass
|
||||||
self.next_button = Hack()
|
self.next_button = Hack()
|
||||||
|
|
||||||
v = lambda x: keystore.is_address_list(x) or keystore.is_private_key_list(x, raise_on_error=True)
|
def is_valid(x) -> bool:
|
||||||
self.slayout = KeysLayout(parent=self, header_layout=header_layout, is_valid=v,
|
return keystore.is_address_list(x) or keystore.is_private_key_list(x, raise_on_error=True)
|
||||||
|
|
||||||
|
self.slayout = KeysLayout(parent=self, header_layout=header_layout, is_valid=is_valid,
|
||||||
allow_multi=True, config=self.wizard.config)
|
allow_multi=True, config=self.wizard.config)
|
||||||
self.layout().addLayout(self.slayout)
|
self.layout().addLayout(self.slayout)
|
||||||
|
|
||||||
@@ -1077,8 +1083,6 @@ class WCChooseHWDevice(WizardComponent, Logger):
|
|||||||
self.layout().addLayout(hbox)
|
self.layout().addLayout(hbox)
|
||||||
self.layout().addStretch(1)
|
self.layout().addStretch(1)
|
||||||
|
|
||||||
self.c_values = []
|
|
||||||
|
|
||||||
def on_ready(self):
|
def on_ready(self):
|
||||||
self.scan_devices()
|
self.scan_devices()
|
||||||
|
|
||||||
@@ -1137,8 +1141,8 @@ class WCChooseHWDevice(WizardComponent, Logger):
|
|||||||
nonlocal debug_msg
|
nonlocal debug_msg
|
||||||
err_str_oneline = ' // '.join(str(e).splitlines())
|
err_str_oneline = ' // '.join(str(e).splitlines())
|
||||||
self.logger.warning(f'error getting device infos for {name}: {err_str_oneline}')
|
self.logger.warning(f'error getting device infos for {name}: {err_str_oneline}')
|
||||||
indented_error_msg = ' '.join([''] + str(e).splitlines(keepends=True))
|
_indented_error_msg = ' '.join([''] + str(e).splitlines(keepends=True))
|
||||||
debug_msg += f' {name}: (error getting device infos)\n{indented_error_msg}\n'
|
debug_msg += f' {name}: (error getting device infos)\n{_indented_error_msg}\n'
|
||||||
|
|
||||||
# scan devices
|
# scan devices
|
||||||
try:
|
try:
|
||||||
@@ -1324,12 +1328,12 @@ class WCHWXPub(WizardComponent, Logger):
|
|||||||
xtype = cosigner_data['script_type']
|
xtype = cosigner_data['script_type']
|
||||||
derivation = cosigner_data['derivation_path']
|
derivation = cosigner_data['derivation_path']
|
||||||
|
|
||||||
def get_xpub_task(client, derivation, xtype):
|
def get_xpub_task(_client, _derivation, _xtype):
|
||||||
try:
|
try:
|
||||||
self.xpub = self.get_xpub_from_client(client, derivation, xtype)
|
self.xpub = self.get_xpub_from_client(_client, _derivation, _xtype)
|
||||||
self.root_fingerprint = client.request_root_fingerprint_from_device()
|
self.root_fingerprint = _client.request_root_fingerprint_from_device()
|
||||||
self.label = client.label()
|
self.label = _client.label()
|
||||||
self.soft_device_id = client.get_soft_device_id()
|
self.soft_device_id = _client.get_soft_device_id()
|
||||||
except UserFacingException as e:
|
except UserFacingException as e:
|
||||||
self.error = str(e)
|
self.error = str(e)
|
||||||
self.logger.error(repr(e))
|
self.logger.error(repr(e))
|
||||||
|
|||||||
Reference in New Issue
Block a user