From f5f177f7e8baebd97418a081f0ae4b93c1024565 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Thu, 27 Apr 2023 09:34:23 +0000 Subject: [PATCH] qml wizard: fix restoring from old mpk (watchonly for "old" seeds) fixes https://github.com/spesmilo/electrum/issues/8356 --- electrum/gui/qml/qebitcoin.py | 31 +++++++++++++++---------------- electrum/gui/qml/qewizard.py | 2 +- electrum/wizard.py | 19 +++++++++++-------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/electrum/gui/qml/qebitcoin.py b/electrum/gui/qml/qebitcoin.py index c0820293a..274f9cd81 100644 --- a/electrum/gui/qml/qebitcoin.py +++ b/electrum/gui/qml/qebitcoin.py @@ -107,28 +107,27 @@ class QEBitcoin(QObject): @pyqtSlot(str, str, result=bool) def verifyMasterKey(self, key, wallet_type='standard'): + # FIXME exceptions raised in here are not well-behaved... self.validationMessage = '' if not keystore.is_master_key(key): self.validationMessage = _('Not a master key') return False k = keystore.from_master_key(key) - has_xpub = isinstance(k, keystore.Xpub) - assert has_xpub - t1 = xpub_type(k.xpub) - - if wallet_type == 'standard': - if t1 not in ['standard', 'p2wpkh', 'p2wpkh-p2sh']: - self.validationMessage = '%s: %s' % (_('Wrong key type'), t1) - return False - return True - elif wallet_type == 'multisig': - if t1 not in ['standard', 'p2wsh', 'p2wsh-p2sh']: - self.validationMessage = '%s: %s' % (_('Wrong key type'), t1) - return False - return True - - raise Exception(f'Unsupported wallet type: {wallet_type}') + if isinstance(k, keystore.Xpub): # has xpub # TODO are these checks useful? + t1 = xpub_type(k.xpub) + if wallet_type == 'standard': + if t1 not in ['standard', 'p2wpkh', 'p2wpkh-p2sh']: + self.validationMessage = '%s: %s' % (_('Wrong key type'), t1) + return False + return True + elif wallet_type == 'multisig': + if t1 not in ['standard', 'p2wsh', 'p2wsh-p2sh']: + self.validationMessage = '%s: %s' % (_('Wrong key type'), t1) + return False + return True + raise Exception(f'Unsupported wallet type: {wallet_type}') + return True @pyqtSlot(str, result=bool) def verifyDerivationPath(self, path): diff --git a/electrum/gui/qml/qewizard.py b/electrum/gui/qml/qewizard.py index a061099c9..5b26fa488 100644 --- a/electrum/gui/qml/qewizard.py +++ b/electrum/gui/qml/qewizard.py @@ -108,7 +108,7 @@ class QENewWalletWizard(NewWalletWizard, QEAbstractWizard): self.createSuccess.emit() except Exception as e: - self._logger.error(repr(e)) + self._logger.error(f"createStorage errored: {e!r}") self.createError.emit(str(e)) class QEServerConnectWizard(ServerConnectWizard, QEAbstractWizard): diff --git a/electrum/wizard.py b/electrum/wizard.py index d46908fc6..072aa4534 100644 --- a/electrum/wizard.py +++ b/electrum/wizard.py @@ -381,15 +381,18 @@ class NewWalletWizard(AbstractWizard): raise Exception('unsupported/unknown seed_type %s' % data['seed_type']) elif data['keystore_type'] == 'masterkey': k = keystore.from_master_key(data['master_key']) - has_xpub = isinstance(k, keystore.Xpub) - assert has_xpub - t1 = xpub_type(k.xpub) - if data['wallet_type'] == 'multisig': - if t1 not in ['standard', 'p2wsh', 'p2wsh-p2sh']: - raise Exception('wrong key type %s' % t1) + if isinstance(k, keystore.Xpub): # has xpub + t1 = xpub_type(k.xpub) + if data['wallet_type'] == 'multisig': + if t1 not in ['standard', 'p2wsh', 'p2wsh-p2sh']: + raise Exception('wrong key type %s' % t1) + else: + if t1 not in ['standard', 'p2wpkh', 'p2wpkh-p2sh']: + raise Exception('wrong key type %s' % t1) + elif isinstance(k, keystore.Old_KeyStore): + pass else: - if t1 not in ['standard', 'p2wpkh', 'p2wpkh-p2sh']: - raise Exception('wrong key type %s' % t1) + raise Exception(f"unexpected keystore type: {type(keystore)}") else: raise Exception('unsupported/unknown keystore_type %s' % data['keystore_type'])