electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit ac5929684699a458b4599b8c6e2dc65519ba94f7
parent 23c8684448f59af48581549b5442ff0f4c50d0ae
Author: ThomasV <thomasv@electrum.org>
Date:   Sat, 22 Oct 2016 10:06:51 +0200

allow spaces in private keys (fix #1602)

Diffstat:
Mgui/qt/installwizard.py | 8++++----
Mgui/qt/main_window.py | 7+++----
Mgui/qt/seed_dialog.py | 21++++++++++++++++++++-
Mgui/qt/util.py | 6------
Mlib/keystore.py | 13+++++++++----
5 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py @@ -11,7 +11,7 @@ from electrum.util import UserCancelled from electrum.base_wizard import BaseWizard from electrum.i18n import _ -from seed_dialog import SeedLayout +from seed_dialog import SeedLayout, KeysLayout from network_dialog import NetworkChoiceLayout from util import * from password_dialog import PasswordLayout, PW_NEW @@ -240,9 +240,9 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard): self.config.remove_from_recently_open(filename) def text_input(self, title, message, is_valid): - slayout = SeedLayout(parent=self, title=message, is_seed=is_valid, icon=False) - self.set_main_layout(slayout.layout(), title, next_enabled=False) - return slayout.get_seed() + slayout = KeysLayout(parent=self, title=message, is_valid=is_valid) + self.set_main_layout(slayout, title, next_enabled=False) + return slayout.get_text() def seed_input(self, title, message, is_seed, options): slayout = SeedLayout(title=message, is_seed=is_seed, options=options, parent=self) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -41,8 +41,8 @@ import PyQt4.QtCore as QtCore import icons_rc +from electrum import keystore from electrum.bitcoin import COIN, is_valid, TYPE_ADDRESS -from electrum.keystore import is_private_key from electrum.plugins import run_hook from electrum.i18n import _ from electrum.util import (block_explorer, block_explorer_info, format_time, @@ -2167,9 +2167,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): return addr def get_pk(): - pk = str(keys_e.toPlainText()).strip() - if is_private_key(pk): - return pk.split() + text = str(keys_e.toPlainText()) + return keystore.get_private_keys(text) f = lambda: button.setEnabled(get_address() is not None and get_pk() is not None) on_address = lambda text: address_e.setStyleSheet(BLACK_FG if get_address() else RED_FG) diff --git a/gui/qt/seed_dialog.py b/gui/qt/seed_dialog.py @@ -133,7 +133,8 @@ class SeedLayout(QVBoxLayout): self.addWidget(WWLabel(msg)) def get_seed(self): - return clean_text(self.seed_e) + text = unicode(self.seed_e.text()) + return ' '.join(text.split()) def on_edit(self): from electrum.bitcoin import seed_type @@ -146,6 +147,24 @@ class SeedLayout(QVBoxLayout): +class KeysLayout(QVBoxLayout): + def __init__(self, parent=None, title=None, is_valid=None): + QVBoxLayout.__init__(self) + self.parent = parent + self.is_valid = is_valid + self.text_e = ScanQRTextEdit() + self.text_e.textChanged.connect(self.on_edit) + self.addWidget(WWLabel(title)) + self.addWidget(self.text_e) + + def get_text(self): + return unicode(self.text_e.text()) + + def on_edit(self): + b = self.is_valid(self.get_text()) + self.parent.next_button.setEnabled(b) + + class SeedDialog(WindowModalDialog): def __init__(self, parent, seed, passphrase): diff --git a/gui/qt/util.py b/gui/qt/util.py @@ -49,12 +49,6 @@ expiration_values = [ ] -def clean_text(seed_e): - text = unicode(seed_e.toPlainText()).strip() - text = ' '.join(text.split()) - return text - - class Timer(QThread): stopped = False diff --git a/lib/keystore.py b/lib/keystore.py @@ -644,14 +644,19 @@ def is_address_list(text): parts = text.split() return bool(parts) and all(bitcoin.is_address(x) for x in parts) -def is_private_key_list(text): - parts = text.split() - return bool(parts) and all(bitcoin.is_private_key(x) for x in parts) +def get_private_keys(text): + parts = text.split('\n') + parts = map(lambda x: ''.join(x.split()), parts) + parts = filter(bool, parts) + if bool(parts) and all(bitcoin.is_private_key(x) for x in parts): + return parts +def is_private_key_list(text): + return bool(get_private_keys(text)) is_mpk = lambda x: is_old_mpk(x) or is_xpub(x) is_private = lambda x: is_seed(x) or is_xprv(x) or is_private_key_list(x) -is_any_key = lambda x: is_old_mpk(x) or is_xprv(x) or is_xpub(x) or is_address_list(x) or is_private_key_list(x) +is_any_key = lambda x: is_old_mpk(x) or is_xprv(x) or is_xpub(x) or is_private_key_list(x) is_private_key = lambda x: is_xprv(x) or is_private_key_list(x) is_bip32_key = lambda x: is_xprv(x) or is_xpub(x)