timportprivkey: do not import the same key twice - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 5733a5d125266fd596922cdf7c1019c520c28272 DIR parent 2e9cfb98001be0de9907366fc4dca71ea30b917d HTML Author: ThomasV <thomasv@electrum.org> Date: Wed, 17 Aug 2016 09:49:58 +0200 importprivkey: do not import the same key twice Diffstat: M gui/qt/main_window.py | 3 +-- M lib/commands.py | 2 +- M lib/keystore.py | 4 +++- 3 files changed, 5 insertions(+), 4 deletions(-) --- DIR diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py t@@ -2208,10 +2208,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): badkeys = [] addrlist = [] for key in text: - addr = self.wallet.import_key(key, password) try: addr = self.wallet.import_key(key, password) - except Exception as e: + except BaseException as e: badkeys.append(key) continue if not addr: DIR diff --git a/lib/commands.py b/lib/commands.py t@@ -368,7 +368,7 @@ class Commands: try: addr = self.wallet.import_key(privkey, self._password) out = "Keypair imported: " + addr - except Exception as e: + except BaseException as e: out = "Error: " + str(e) return out DIR diff --git a/lib/keystore.py b/lib/keystore.py t@@ -115,7 +115,9 @@ class Imported_KeyStore(Software_KeyStore): try: pubkey = public_key_from_private_key(sec) except Exception: - raise Exception('Invalid private key') + raise BaseException('Invalid private key') + if pubkey in self.keypairs: + raise BaseException('Private key already in keystore') self.keypairs[pubkey] = sec return pubkey