From 75195b667a78c59f25b4bd5da76f3ee47ccc98c3 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Fri, 5 Sep 2025 16:10:33 +0000 Subject: [PATCH] keystore: get_private_keys should not return None closes https://github.com/spesmilo/electrum/issues/10200 --- electrum/gui/qt/main_window.py | 4 ++-- electrum/keystore.py | 4 ++-- electrum/wallet.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index 45783aa78..bfef3e3b1 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -2592,14 +2592,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): if bitcoin.is_address(addr): return addr - def get_pk(*, raise_on_error=False): + def get_pk(*, raise_on_error=False) -> Sequence[str]: text = str(keys_e.toPlainText()) return keystore.get_private_keys(text, raise_on_error=raise_on_error) def on_edit(): valid_privkeys = False try: - valid_privkeys = get_pk(raise_on_error=True) is not None + valid_privkeys = bool(get_pk(raise_on_error=True)) except Exception as e: button.setToolTip(f'{_("Error")}: {repr(e)}') else: diff --git a/electrum/keystore.py b/electrum/keystore.py index 340dcd41f..65c4ec389 100644 --- a/electrum/keystore.py +++ b/electrum/keystore.py @@ -1134,7 +1134,7 @@ def is_address_list(text: str) -> bool: return bool(parts) and all(bitcoin.is_address(x) for x in parts) -def get_private_keys(text: str, *, allow_spaces_inside_key=True, raise_on_error=False) -> Optional[Sequence[str]]: +def get_private_keys(text: str, *, allow_spaces_inside_key=True, raise_on_error=False) -> Sequence[str]: if allow_spaces_inside_key: # see #1612 parts = text.split('\n') parts = map(lambda x: ''.join(x.split()), parts) @@ -1143,7 +1143,7 @@ def get_private_keys(text: str, *, allow_spaces_inside_key=True, raise_on_error= parts = text.split() if bool(parts) and all(bitcoin.is_private_key(x, raise_on_error=raise_on_error) for x in parts): return parts - return None + return [] def is_private_key_list(text: str, *, allow_spaces_inside_key: bool = True, raise_on_error: bool = False) -> bool: diff --git a/electrum/wallet.py b/electrum/wallet.py index e28778abd..843d521ab 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -3755,7 +3755,7 @@ class Imported_Wallet(Simple_Wallet): x = self.db.get_imported_address(address) return x.get('pubkey') if x else None - def import_private_keys(self, keys: List[str], password: Optional[str], *, + def import_private_keys(self, keys: Sequence[str], password: Optional[str], *, write_to_disk=True) -> Tuple[List[str], List[Tuple[str, str]]]: good_addr = [] # type: List[str] bad_keys = [] # type: List[Tuple[str, str]]