Browse Source

QEDaemon uses internal QEWalletDB for wallet open pre-checks

various other fixes
patch-4
Sander van Grieken 3 years ago
parent
commit
e1f53c4ea0
  1. 14
      electrum/gui/qml/components/Wallets.qml
  2. 1
      electrum/gui/qml/qeaddressdetails.py
  3. 28
      electrum/gui/qml/qedaemon.py
  4. 6
      electrum/gui/qml/qetransactionlistmodel.py
  5. 4
      electrum/gui/qml/qewallet.py
  6. 15
      electrum/gui/qml/qewalletdb.py

14
electrum/gui/qml/components/Wallets.qml

@ -30,8 +30,8 @@ Pane {
Label { text: 'Wallet'; Layout.columnSpan: 2 } Label { text: 'Wallet'; Layout.columnSpan: 2 }
Label { text: Daemon.currentWallet.name; Layout.columnSpan: 2; color: Material.accentColor } Label { text: Daemon.currentWallet.name; Layout.columnSpan: 2; color: Material.accentColor }
Label { text: 'derivation path (BIP32)'; visible: Daemon.currentWallet.isDeterministic; Layout.columnSpan: 2 } Label { text: 'derivation prefix (BIP32)'; visible: Daemon.currentWallet.isDeterministic; Layout.columnSpan: 2 }
Label { text: Daemon.currentWallet.derivationPath; visible: Daemon.currentWallet.isDeterministic; color: Material.accentColor; Layout.columnSpan: 2 } Label { text: Daemon.currentWallet.derivationPrefix; visible: Daemon.currentWallet.isDeterministic; color: Material.accentColor; Layout.columnSpan: 2 }
Label { text: 'txinType' } Label { text: 'txinType' }
Label { text: Daemon.currentWallet.txinType; color: Material.accentColor } Label { text: Daemon.currentWallet.txinType; color: Material.accentColor }
@ -69,9 +69,6 @@ Pane {
delegate: AbstractButton { delegate: AbstractButton {
width: ListView.view.width width: ListView.view.width
height: row.height height: row.height
onClicked: {
wallet_db.path = model.path
}
RowLayout { RowLayout {
id: row id: row
@ -83,8 +80,8 @@ Pane {
id: walleticon id: walleticon
source: "../../icons/wallet.png" source: "../../icons/wallet.png"
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
Layout.preferredWidth: 32 Layout.preferredWidth: constants.iconSizeLarge
Layout.preferredHeight: 32 Layout.preferredHeight: constants.iconSizeLarge
} }
Label { Label {
@ -129,7 +126,4 @@ Pane {
} }
} }
WalletDB {
id: wallet_db
}
} }

1
electrum/gui/qml/qeaddressdetails.py

@ -109,4 +109,5 @@ class QEAddressDetails(QObject):
self._balance = QEAmount(amount_sat=c + u + x) self._balance = QEAmount(amount_sat=c + u + x)
self._pubkeys = self._wallet.wallet.get_public_keys(self._address) self._pubkeys = self._wallet.wallet.get_public_keys(self._address)
self._derivationPath = self._wallet.wallet.get_address_path_str(self._address) self._derivationPath = self._wallet.wallet.get_address_path_str(self._address)
self._derivationPath = self._derivationPath.replace('m', self._wallet.derivationPrefix)
self.detailsChanged.emit() self.detailsChanged.emit()

28
electrum/gui/qml/qedaemon.py

@ -8,8 +8,10 @@ from electrum.util import register_callback, get_new_wallet_name, WalletFileExce
from electrum.logging import get_logger from electrum.logging import get_logger
from electrum.wallet import Wallet, Abstract_Wallet from electrum.wallet import Wallet, Abstract_Wallet
from electrum.storage import WalletStorage, StorageReadWriteError from electrum.storage import WalletStorage, StorageReadWriteError
from electrum.wallet_db import WalletDB
from .qewallet import QEWallet from .qewallet import QEWallet
from .qewalletdb import QEWalletDB
from .qefx import QEFX from .qefx import QEFX
# wallet list model. supports both wallet basenames (wallet file basenames) # wallet list model. supports both wallet basenames (wallet file basenames)
@ -87,6 +89,8 @@ class QEDaemon(QObject):
super().__init__(parent) super().__init__(parent)
self.daemon = daemon self.daemon = daemon
self.qefx = QEFX(daemon.fx, daemon.config) self.qefx = QEFX(daemon.fx, daemon.config)
self._walletdb = QEWalletDB()
self._walletdb.invalidPasswordChanged.connect(self.passwordValidityCheck)
_logger = get_logger(__name__) _logger = get_logger(__name__)
_loaded_wallets = QEWalletListModel() _loaded_wallets = QEWalletListModel()
@ -94,6 +98,7 @@ class QEDaemon(QObject):
_current_wallet = None _current_wallet = None
_path = None _path = None
walletLoaded = pyqtSignal() walletLoaded = pyqtSignal()
walletRequiresPassword = pyqtSignal() walletRequiresPassword = pyqtSignal()
activeWalletsChanged = pyqtSignal() activeWalletsChanged = pyqtSignal()
@ -101,6 +106,11 @@ class QEDaemon(QObject):
walletOpenError = pyqtSignal([str], arguments=["error"]) walletOpenError = pyqtSignal([str], arguments=["error"])
fxChanged = pyqtSignal() fxChanged = pyqtSignal()
@pyqtSlot()
def passwordValidityCheck(self):
if self._walletdb._invalidPassword:
self.walletRequiresPassword.emit()
@pyqtSlot() @pyqtSlot()
@pyqtSlot(str) @pyqtSlot(str)
@pyqtSlot(str, str) @pyqtSlot(str, str)
@ -113,14 +123,13 @@ class QEDaemon(QObject):
return return
self._logger.debug('load wallet ' + str(self._path)) self._logger.debug('load wallet ' + str(self._path))
try:
storage = WalletStorage(self._path) if path not in self.daemon._wallets:
if not storage.file_exists(): # pre-checks, let walletdb trigger any necessary user interactions
self.walletOpenError.emit('File not found') self._walletdb.path = self._path
self._walletdb.password = password
if not self._walletdb.ready:
return return
except StorageReadWriteError as e:
self.walletOpenError.emit('Storage read/write error')
return
try: try:
wallet = self.daemon.load_wallet(self._path, password) wallet = self.daemon.load_wallet(self._path, password)
@ -130,8 +139,8 @@ class QEDaemon(QObject):
self.walletLoaded.emit() self.walletLoaded.emit()
self.daemon.config.save_last_wallet(wallet) self.daemon.config.save_last_wallet(wallet)
else: else:
self._logger.info('password required but unset or incorrect') self._logger.info('could not open wallet')
self.walletRequiresPassword.emit() self.walletOpenError.emit('could not open wallet')
except WalletFileException as e: except WalletFileException as e:
self._logger.error(str(e)) self._logger.error(str(e))
self.walletOpenError.emit(str(e)) self.walletOpenError.emit(str(e))
@ -159,4 +168,3 @@ class QEDaemon(QObject):
@pyqtProperty(QEFX, notify=fxChanged) @pyqtProperty(QEFX, notify=fxChanged)
def fx(self): def fx(self):
return self.qefx return self.qefx

6
electrum/gui/qml/qetransactionlistmodel.py

@ -85,8 +85,10 @@ class QETransactionListModel(QAbstractListModel):
'lastweek': '%a, %H:%M:%S', 'lastweek': '%a, %H:%M:%S',
'lastmonth': '%a %d, %H:%M:%S', 'lastmonth': '%a %d, %H:%M:%S',
'older': '%G-%m-%d %H:%M:%S' 'older': '%G-%m-%d %H:%M:%S'
}[section] }
return date.strftime(dfmt) if section not in dfmt:
section = 'older'
return date.strftime(dfmt[section])
# initial model data # initial model data
def init_model(self): def init_model(self):

4
electrum/gui/qml/qewallet.py

@ -139,7 +139,7 @@ class QEWallet(QObject):
self._logger.debug('queue empty, stopping wallet notification timer') self._logger.debug('queue empty, stopping wallet notification timer')
self.notification_timer.stop() self.notification_timer.stop()
return return
if not self.wallet.up_to_date: if not self.wallet.is_up_to_date():
return # no notifications while syncing return # no notifications while syncing
now = time.time() now = time.time()
rate_limit = 20 # seconds rate_limit = 20 # seconds
@ -218,7 +218,7 @@ class QEWallet(QObject):
return self.wallet.storage.is_encrypted_with_hw_device() return self.wallet.storage.is_encrypted_with_hw_device()
@pyqtProperty('QString', notify=dataChanged) @pyqtProperty('QString', notify=dataChanged)
def derivationPath(self): def derivationPrefix(self):
keystores = self.wallet.get_keystores() keystores = self.wallet.get_keystores()
if len(keystores) > 1: if len(keystores) > 1:
self._logger.debug('multiple keystores not supported yet') self._logger.debug('multiple keystores not supported yet')

15
electrum/gui/qml/qewalletdb.py

@ -9,8 +9,6 @@ from electrum.bip32 import normalize_bip32_derivation
from electrum.util import InvalidPassword from electrum.util import InvalidPassword
from electrum import keystore from electrum import keystore
from .qedaemon import QEDaemon
class QEWalletDB(QObject): class QEWalletDB(QObject):
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent) super().__init__(parent)
@ -116,6 +114,12 @@ class QEWalletDB(QObject):
def invalidPassword(self): def invalidPassword(self):
return self._invalidPassword return self._invalidPassword
@invalidPassword.setter
def invalidPassword(self, invalidPassword):
if self._invalidPassword != invalidPassword:
self._invalidPassword = invalidPassword
self.invalidPasswordChanged.emit()
@pyqtProperty(bool, notify=readyChanged) @pyqtProperty(bool, notify=readyChanged)
def ready(self): def ready(self):
return self._ready return self._ready
@ -143,11 +147,10 @@ class QEWalletDB(QObject):
self.needsPassword = True self.needsPassword = True
try: try:
self._storage.decrypt(self._password) self._storage.decrypt('' if not self._password else self._password)
self._invalidPassword = False self.invalidPassword = False
except InvalidPassword as e: except InvalidPassword as e:
self._invalidPassword = True self.invalidPassword = True
self.invalidPasswordChanged.emit()
if not self._storage.is_past_initial_decryption(): if not self._storage.is_past_initial_decryption():
self._storage = None self._storage = None

Loading…
Cancel
Save