allow spaces in private keys (fix #1602)
This commit is contained in:
parent
23c8684448
commit
ac59296846
@ -11,7 +11,7 @@ from electrum.util import UserCancelled
|
|||||||
from electrum.base_wizard import BaseWizard
|
from electrum.base_wizard import BaseWizard
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
|
|
||||||
from seed_dialog import SeedLayout
|
from seed_dialog import SeedLayout, KeysLayout
|
||||||
from network_dialog import NetworkChoiceLayout
|
from network_dialog import NetworkChoiceLayout
|
||||||
from util import *
|
from util import *
|
||||||
from password_dialog import PasswordLayout, PW_NEW
|
from password_dialog import PasswordLayout, PW_NEW
|
||||||
@ -240,9 +240,9 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
|
|||||||
self.config.remove_from_recently_open(filename)
|
self.config.remove_from_recently_open(filename)
|
||||||
|
|
||||||
def text_input(self, title, message, is_valid):
|
def text_input(self, title, message, is_valid):
|
||||||
slayout = SeedLayout(parent=self, title=message, is_seed=is_valid, icon=False)
|
slayout = KeysLayout(parent=self, title=message, is_valid=is_valid)
|
||||||
self.set_main_layout(slayout.layout(), title, next_enabled=False)
|
self.set_main_layout(slayout, title, next_enabled=False)
|
||||||
return slayout.get_seed()
|
return slayout.get_text()
|
||||||
|
|
||||||
def seed_input(self, title, message, is_seed, options):
|
def seed_input(self, title, message, is_seed, options):
|
||||||
slayout = SeedLayout(title=message, is_seed=is_seed, options=options, parent=self)
|
slayout = SeedLayout(title=message, is_seed=is_seed, options=options, parent=self)
|
||||||
|
|||||||
@ -41,8 +41,8 @@ import PyQt4.QtCore as QtCore
|
|||||||
|
|
||||||
import icons_rc
|
import icons_rc
|
||||||
|
|
||||||
|
from electrum import keystore
|
||||||
from electrum.bitcoin import COIN, is_valid, TYPE_ADDRESS
|
from electrum.bitcoin import COIN, is_valid, TYPE_ADDRESS
|
||||||
from electrum.keystore import is_private_key
|
|
||||||
from electrum.plugins import run_hook
|
from electrum.plugins import run_hook
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.util import (block_explorer, block_explorer_info, format_time,
|
from electrum.util import (block_explorer, block_explorer_info, format_time,
|
||||||
@ -2167,9 +2167,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||||||
return addr
|
return addr
|
||||||
|
|
||||||
def get_pk():
|
def get_pk():
|
||||||
pk = str(keys_e.toPlainText()).strip()
|
text = str(keys_e.toPlainText())
|
||||||
if is_private_key(pk):
|
return keystore.get_private_keys(text)
|
||||||
return pk.split()
|
|
||||||
|
|
||||||
f = lambda: button.setEnabled(get_address() is not None and get_pk() is not None)
|
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)
|
on_address = lambda text: address_e.setStyleSheet(BLACK_FG if get_address() else RED_FG)
|
||||||
|
|||||||
@ -133,7 +133,8 @@ class SeedLayout(QVBoxLayout):
|
|||||||
self.addWidget(WWLabel(msg))
|
self.addWidget(WWLabel(msg))
|
||||||
|
|
||||||
def get_seed(self):
|
def get_seed(self):
|
||||||
return clean_text(self.seed_e)
|
text = unicode(self.seed_e.text())
|
||||||
|
return ' '.join(text.split())
|
||||||
|
|
||||||
def on_edit(self):
|
def on_edit(self):
|
||||||
from electrum.bitcoin import seed_type
|
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):
|
class SeedDialog(WindowModalDialog):
|
||||||
|
|
||||||
def __init__(self, parent, seed, passphrase):
|
def __init__(self, parent, seed, passphrase):
|
||||||
|
|||||||
@ -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):
|
class Timer(QThread):
|
||||||
stopped = False
|
stopped = False
|
||||||
|
|
||||||
|
|||||||
@ -644,14 +644,19 @@ def is_address_list(text):
|
|||||||
parts = text.split()
|
parts = text.split()
|
||||||
return bool(parts) and all(bitcoin.is_address(x) for x in parts)
|
return bool(parts) and all(bitcoin.is_address(x) for x in parts)
|
||||||
|
|
||||||
def is_private_key_list(text):
|
def get_private_keys(text):
|
||||||
parts = text.split()
|
parts = text.split('\n')
|
||||||
return bool(parts) and all(bitcoin.is_private_key(x) for x in parts)
|
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_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_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_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)
|
is_bip32_key = lambda x: is_xprv(x) or is_xpub(x)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user