From 71429ef4bd67dbe5a45aef6bbb0d8e5d3d1c3fc3 Mon Sep 17 00:00:00 2001 From: thomasv Date: Thu, 31 Oct 2013 17:00:20 +0100 Subject: [PATCH 01/17] no keyid for imported keys --- lib/wallet.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/wallet.py b/lib/wallet.py index c8f11a936..41102cf62 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -1328,6 +1328,8 @@ class Wallet: def add_input_info(self, inputs): for txin in inputs: address = txin['address'] + if address in self.imported_keys.keys(): + continue account, sequence = self.get_address_index(address) txin['KeyID'] = self.get_keyID(account, sequence) redeemScript = self.accounts[account].redeem_script(sequence) From a9159729aaed9cfb07ecc8f8536f51e580448fe7 Mon Sep 17 00:00:00 2001 From: thomasv Date: Thu, 31 Oct 2013 17:50:23 +0100 Subject: [PATCH 02/17] release notes: bip32 featues are postponed --- RELEASE-NOTES | 2 -- 1 file changed, 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 05138c29d..bc141ca8a 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -2,9 +2,7 @@ * The client connects to multiple servers in order to retrieve block headers and find the longest chain * SSL certificate validation (to prevent MITM) -* Implements BIP32 (hierarchical deterministic wallet) * Deterministic signatures (RFC 6979) -* Can create multiple accounts in the same wallet * Menu to create/restore/open wallets * Create transactions with multiple outputs from CSV (comma separated values) * New text gui: stdio From 999bf3d2fd7922c6b96431816a999a069a15451e Mon Sep 17 00:00:00 2001 From: ThomasV Date: Fri, 1 Nov 2013 10:34:29 +0100 Subject: [PATCH 03/17] minor fix: restore from hexadecimal seed --- lib/wallet.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/wallet.py b/lib/wallet.py index 41102cf62..450f6744f 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -311,6 +311,7 @@ class Wallet: try: seed.decode('hex') self.seed_version = 4 + self.seed = str(seed) return except: pass From 4f3497027d6b05664402b08c33863bfa9a492469 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Fri, 1 Nov 2013 12:40:53 +0100 Subject: [PATCH 04/17] fix deseed --- electrum | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/electrum b/electrum index ffa4eb951..ecef1f304 100755 --- a/electrum +++ b/electrum @@ -349,16 +349,16 @@ if __name__ == '__main__': if not wallet.seed: print_msg("Error: This wallet has no seed") else: - ns = wallet.config.path + '.seedless' + ns = wallet.storage.path + '.seedless' print_msg("Warning: you are going to create a seedless wallet'\nIt will be saved in '%s'"%ns) if raw_input("Are you sure you want to continue? (y/n) ") in ['y','Y','yes']: - wallet.config.path = ns + wallet.storage.path = ns wallet.seed = '' wallet.storage.put('seed', '', True) wallet.use_encryption = False wallet.storage.put('use_encryption', wallet.use_encryption, True) for k in wallet.imported_keys.keys(): wallet.imported_keys[k] = '' - wallet.config.set_key('imported_keys',wallet.imported_keys, True) + wallet.storage.put('imported_keys',wallet.imported_keys, True) print_msg("Done.") else: print_msg("Action canceled.") From cf38e1e47c80cbaff0d63edfc83276c072523cb5 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Fri, 1 Nov 2013 13:10:27 +0100 Subject: [PATCH 05/17] fix: offline signing --- lib/transaction.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/transaction.py b/lib/transaction.py index ad647748a..7e36369d1 100644 --- a/lib/transaction.py +++ b/lib/transaction.py @@ -432,10 +432,12 @@ class Transaction: pubkeys = txin['pubkeys'] if not txin.get('redeemScript'): pubkey = pubkeys[0] - sig = signatures[0] - sig = sig + '01' # hashtype - script = op_push(len(sig)/2) - script += sig + script = '' + if signatures: + sig = signatures[0] + sig = sig + '01' # hashtype + script += op_push(len(sig)/2) + script += sig script += op_push(len(pubkey)/2) script += pubkey else: @@ -720,6 +722,7 @@ class Transaction: for i, txin in enumerate(self.inputs): item = input_info[i] txin['address'] = item['address'] + txin['signatures'] = item['signatures'] txin['scriptPubKey'] = item['scriptPubKey'] txin['redeemScript'] = item.get('redeemScript') txin['redeemPubkey'] = item.get('redeemPubkey') From 67d185d7f0878e9862b845a2cdd85a86524c3975 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Fri, 1 Nov 2013 13:31:13 +0100 Subject: [PATCH 06/17] offline signing with seed_v4 --- lib/wallet.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/wallet.py b/lib/wallet.py index 450f6744f..f9b9c7944 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -650,7 +650,9 @@ class Wallet: def get_keyID(self, account, sequence): if account == 0: - return 'old' + a, b = sequence + mpk = self.storage.get('master_public_key') + return 'old(%s,%d,%d)'%(mpk,a,b) rs = self.rebase_sequence(account, sequence) dd = [] @@ -720,6 +722,24 @@ class Wallet: for txin in tx.inputs: keyid = txin.get('KeyID') if keyid: + + if self.seed_version==4: + m = re.match("old\(([0-9a-f]+),(\d+),(\d+)", keyid) + if not m: continue + mpk = m.group(1) + if mpk != self.storage.get('master_public_key'): continue + index = int(m.group(2)) + num = int(m.group(3)) + account = self.accounts[0] + addr = account.get_address(index, num) + txin['address'] = addr # fixme: side effect + pk = self.get_private_key(addr, password) + for sec in pk: + pubkey = public_key_from_private_key(sec) + keypairs[pubkey] = sec + continue + + roots = [] for s in keyid.split('&'): m = re.match("bip32\(([0-9a-f]+),([0-9a-f]+),(/\d+/\d+/\d+)", s) From cf5252e6aae1ad504bfab3a5c06c9de2d529ef8f Mon Sep 17 00:00:00 2001 From: Ryan McGuire Date: Fri, 1 Nov 2013 14:58:19 -0400 Subject: [PATCH 07/17] Fixes qrscanner to 1.9 API. --- plugins/qrscanner.py | 72 +++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/plugins/qrscanner.py b/plugins/qrscanner.py index 381405e44..c7a0e58e8 100644 --- a/plugins/qrscanner.py +++ b/plugins/qrscanner.py @@ -39,24 +39,26 @@ class Plugin(BasePlugin): return True - def is_available(self): - return self._is_available - - def create_send_tab(self, grid): + def load_wallet(self, wallet): b = QPushButton(_("Scan QR code")) b.clicked.connect(self.fill_from_qr) - grid.addWidget(b, 1, 5) + self.send_tab_grid.addWidget(b, 1, 5) b2 = QPushButton(_("Scan TxQR")) b2.clicked.connect(self.read_raw_qr) - if not self.gui.wallet.seed: + if not wallet.seed: b3 = QPushButton(_("Show unsigned TxQR")) b3.clicked.connect(self.show_raw_qr) - grid.addWidget(b3, 7, 1) - grid.addWidget(b2, 7, 2) + self.send_tab_grid.addWidget(b3, 7, 1) + self.send_tab_grid.addWidget(b2, 7, 2) else: - grid.addWidget(b2, 7, 1) + self.send_tab_grid.addWidget(b2, 7, 1) + def is_available(self): + return self._is_available + + def create_send_tab(self, grid): + self.send_tab_grid = grid def scan_qr(self): proc = zbar.Processor() @@ -76,7 +78,7 @@ class Plugin(BasePlugin): return r.data def show_raw_qr(self): - r = unicode( self.gui.payto_e.text() ) + r = unicode( self.gui.main_window.payto_e.text() ) r = r.strip() # label or alias, with address in brackets @@ -84,28 +86,28 @@ class Plugin(BasePlugin): to_address = m.group(2) if m else r if not is_valid(to_address): - QMessageBox.warning(self.gui, _('Error'), _('Invalid Bitcoin Address') + ':\n' + to_address, _('OK')) + QMessageBox.warning(self.gui.main_window, _('Error'), _('Invalid Bitcoin Address') + ':\n' + to_address, _('OK')) return try: - amount = self.gui.read_amount(unicode( self.gui.amount_e.text())) + amount = self.gui.main_window.read_amount(unicode( self.gui.main_window.amount_e.text())) except: - QMessageBox.warning(self.gui, _('Error'), _('Invalid Amount'), _('OK')) + QMessageBox.warning(self.gui.main_window, _('Error'), _('Invalid Amount'), _('OK')) return try: - fee = self.gui.read_amount(unicode( self.gui.fee_e.text())) + fee = self.gui.main_window.read_amount(unicode( self.gui.main_window.fee_e.text())) except: - QMessageBox.warning(self.gui, _('Error'), _('Invalid Fee'), _('OK')) + QMessageBox.warning(self.gui.main_window, _('Error'), _('Invalid Fee'), _('OK')) return try: - tx = self.gui.wallet.mktx( [(to_address, amount)], None, fee, account=self.gui.current_account) + tx = self.gui.main_window.wallet.mktx( [(to_address, amount)], None, fee) except BaseException, e: - self.gui.show_message(str(e)) + self.gui.main_window.show_message(str(e)) return - if tx.requires_fee(self.gui.wallet.verifier) and fee < MIN_RELAY_TX_FEE: - QMessageBox.warning(self.gui, _('Error'), _("This transaction requires a higher fee, or it will not be propagated by the network."), _('OK')) + if tx.requires_fee(self.gui.main_window.wallet.verifier) and fee < MIN_RELAY_TX_FEE: + QMessageBox.warning(self.gui.main_window, _('Error'), _("This transaction requires a higher fee, or it will not be propagated by the network."), _('OK')) return try: @@ -117,17 +119,17 @@ class Plugin(BasePlugin): input_info = [] except BaseException, e: - self.gui.show_message(str(e)) + self.gui.main_window.show_message(str(e)) try: json_text = json.dumps(tx.as_dict()).replace(' ', '') self.show_tx_qrcode(json_text, 'Unsigned Transaction') except BaseException, e: - self.gui.show_message(str(e)) + self.gui.main_window.show_message(str(e)) def show_tx_qrcode(self, data, title): if not data: return - d = QDialog(self.gui) + d = QDialog(self.gui.main_window) d.setModal(1) d.setWindowTitle(title) d.setMinimumSize(250, 525) @@ -158,7 +160,7 @@ class Plugin(BasePlugin): def read_raw_qr(self): qrcode = self.scan_qr() if qrcode: - tx_dict = self.gui.tx_dict_from_text(qrcode) + tx_dict = self.gui.main_window.tx_dict_from_text(qrcode) if tx_dict: self.create_transaction_details_window(tx_dict) @@ -166,7 +168,7 @@ class Plugin(BasePlugin): def create_transaction_details_window(self, tx_dict): tx = Transaction(tx_dict["hex"]) - dialog = QDialog(self.gui) + dialog = QDialog(self.gui.main_window) dialog.setMinimumWidth(500) dialog.setWindowTitle(_('Process Offline transaction')) dialog.setModal(1) @@ -179,7 +181,7 @@ class Plugin(BasePlugin): if tx_dict["complete"] == False: l.addWidget(QLabel(_("Unsigned")), 3,1) - if self.gui.wallet.seed : + if self.gui.main_window.wallet.seed : b = QPushButton("Sign transaction") input_info = json.loads(tx_dict["input_info"]) b.clicked.connect(lambda: self.sign_raw_transaction(tx, input_info, dialog)) @@ -189,10 +191,10 @@ class Plugin(BasePlugin): else: l.addWidget(QLabel(_("Signed")), 3,1) b = QPushButton("Broadcast transaction") - b.clicked.connect(lambda: self.gui.send_raw_transaction(tx, dialog)) + b.clicked.connect(lambda: self.gui.main_window.send_raw_transaction(tx, dialog)) l.addWidget(b,4,1) - l.addWidget( self.gui.generate_transaction_information_widget(tx), 0,0,2,3) + l.addWidget( self.gui.main_window.generate_transaction_information_widget(tx), 0,0,2,3) closeButton = QPushButton(_("Close")) closeButton.clicked.connect(lambda: dialog.done(0)) l.addWidget(closeButton, 4,2) @@ -200,8 +202,8 @@ class Plugin(BasePlugin): dialog.exec_() def do_protect(self, func, args): - if self.gui.wallet.use_encryption: - password = self.gui.password_dialog() + if self.gui.main_window.wallet.use_encryption: + password = self.gui.main_window.password_dialog() if not password: return else: @@ -219,11 +221,11 @@ class Plugin(BasePlugin): @protected def sign_raw_transaction(self, tx, input_info, dialog ="", password = ""): try: - self.gui.wallet.signrawtransaction(tx, input_info, [], password) + self.gui.main_window.wallet.signrawtransaction(tx, input_info, [], password) txtext = json.dumps(tx.as_dict()).replace(' ', '') self.show_tx_qrcode(txtext, 'Signed Transaction') except BaseException, e: - self.gui.show_message(str(e)) + self.gui.main_window.show_message(str(e)) def fill_from_qr(self): @@ -232,13 +234,13 @@ class Plugin(BasePlugin): return if 'address' in qrcode: - self.gui.payto_e.setText(qrcode['address']) + self.gui.main_window.payto_e.setText(qrcode['address']) if 'amount' in qrcode: - self.gui.amount_e.setText(str(qrcode['amount'])) + self.gui.main_window.amount_e.setText(str(qrcode['amount'])) if 'label' in qrcode: - self.gui.message_e.setText(qrcode['label']) + self.gui.main_window.message_e.setText(qrcode['label']) if 'message' in qrcode: - self.gui.message_e.setText("%s (%s)" % (self.gui.message_e.text(), qrcode['message'])) + self.gui.main_window.message_e.setText("%s (%s)" % (self.gui.main_window.message_e.text(), qrcode['message'])) From 56168e85b8e469f9c042eda6704a31d016efe26a Mon Sep 17 00:00:00 2001 From: Ryan McGuire Date: Fri, 1 Nov 2013 21:18:36 -0400 Subject: [PATCH 08/17] Adds a settings dialog for qrscanner plugin - allows device selection --- plugins/qrscanner.py | 98 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 4 deletions(-) diff --git a/plugins/qrscanner.py b/plugins/qrscanner.py index c7a0e58e8..e8849ad37 100644 --- a/plugins/qrscanner.py +++ b/plugins/qrscanner.py @@ -1,14 +1,16 @@ from electrum.util import print_error from urlparse import urlparse, parse_qs -from PyQt4.QtGui import QPushButton, QMessageBox, QDialog, QVBoxLayout, QHBoxLayout, QGridLayout, QLabel +from PyQt4.QtGui import QPushButton, QMessageBox, QDialog, QVBoxLayout, QHBoxLayout, QGridLayout, QLabel, QLineEdit, QComboBox from PyQt4.QtCore import Qt from electrum.i18n import _ import re +import os from electrum import Transaction from electrum.bitcoin import MIN_RELAY_TX_FEE, is_valid from electrum_gui.qt.qrcodewidget import QRCodeWidget from electrum import bmp +from electrum_gui.qt import HelpButton, EnterButton import json try: @@ -32,10 +34,11 @@ class Plugin(BasePlugin): return False try: proc = zbar.Processor() - proc.init() + proc.init(video_device=self.video_device()) except zbar.SystemError: # Cannot open video device - return False + pass + #return False return True @@ -62,7 +65,12 @@ class Plugin(BasePlugin): def scan_qr(self): proc = zbar.Processor() - proc.init() + try: + proc.init(video_device=self.video_device()) + except zbar.SystemError, e: + QMessageBox.warning(self.gui.main_window, _('Error'), _(e), _('OK')) + return + proc.visible = True while True: @@ -242,6 +250,88 @@ class Plugin(BasePlugin): if 'message' in qrcode: self.gui.main_window.message_e.setText("%s (%s)" % (self.gui.main_window.message_e.text(), qrcode['message'])) + def video_device(self): + device = self.config.get("video_device", "default") + if device == 'default': + device = '' + return device + + def requires_settings(self): + return True + + def settings_widget(self, window): + return EnterButton(_('Settings'), self.settings_dialog) + + def _find_system_cameras(self): + device_root = "/sys/class/video4linux" + devices = {} # Name -> device + if os.path.exists(device_root): + for device in os.listdir(device_root): + name = open(os.path.join(device_root, device, 'name')).read() + devices[name] = os.path.join("/dev",device) + return devices + + def settings_dialog(self): + system_cameras = self._find_system_cameras() + + d = QDialog() + layout = QGridLayout(d) + layout.addWidget(QLabel("Choose a video device:"),0,0) + + # Create a combo box with the available video devices: + combo = QComboBox() + + # on change trigger for video device selection, makes the + # manual device selection only appear when needed: + def on_change(x): + combo_text = str(combo.itemText(x)) + combo_data = combo.itemData(x) + if combo_text == "Manually specify a device": + custom_device_label.setVisible(True) + self.video_device_edit.setVisible(True) + if self.config.get("video_device") == "default": + self.video_device_edit.setText("") + else: + self.video_device_edit.setText(self.config.get("video_device")) + else: + custom_device_label.setVisible(False) + self.video_device_edit.setVisible(False) + self.video_device_edit.setText(combo_data.toString()) + + # on save trigger for the video device selection window, + # stores the chosen video device on close. + def on_save(): + device = str(self.video_device_edit.text()) + self.config.set_key("video_device", device) + d.accept() + + custom_device_label = QLabel("Video device: ") + custom_device_label.setVisible(False) + layout.addWidget(custom_device_label,1,0) + self.video_device_edit = QLineEdit() + self.video_device_edit.setVisible(False) + layout.addWidget(self.video_device_edit, 1,1,2,2) + combo.currentIndexChanged.connect(on_change) + + combo.addItem("Default","default") + for camera, device in system_cameras.items(): + combo.addItem(camera, device) + combo.addItem("Manually specify a device",self.config.get("video_device")) + + # Populate the previously chosen device: + index = combo.findData(self.config.get("video_device")) + combo.setCurrentIndex(index) + + layout.addWidget(combo,0,1) + + self.accept = QPushButton(_("Done")) + self.accept.clicked.connect(on_save) + layout.addWidget(self.accept,4,2) + + if d.exec_(): + return True + else: + return False From 77dd9a0c8bfcdeca4d778c9f1ab89f766fe82320 Mon Sep 17 00:00:00 2001 From: Ryan McGuire Date: Fri, 1 Nov 2013 22:18:14 -0400 Subject: [PATCH 09/17] Fixes sending coins from the qrscanner plugin --- plugins/qrscanner.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/plugins/qrscanner.py b/plugins/qrscanner.py index e8849ad37..d76742d91 100644 --- a/plugins/qrscanner.py +++ b/plugins/qrscanner.py @@ -168,14 +168,11 @@ class Plugin(BasePlugin): def read_raw_qr(self): qrcode = self.scan_qr() if qrcode: - tx_dict = self.gui.main_window.tx_dict_from_text(qrcode) - if tx_dict: - self.create_transaction_details_window(tx_dict) + tx = self.gui.main_window.tx_from_text(qrcode) + if tx: + self.create_transaction_details_window(tx) - - def create_transaction_details_window(self, tx_dict): - tx = Transaction(tx_dict["hex"]) - + def create_transaction_details_window(self, tx): dialog = QDialog(self.gui.main_window) dialog.setMinimumWidth(500) dialog.setWindowTitle(_('Process Offline transaction')) @@ -187,22 +184,28 @@ class Plugin(BasePlugin): l.addWidget(QLabel(_("Transaction status:")), 3,0) l.addWidget(QLabel(_("Actions")), 4,0) - if tx_dict["complete"] == False: + if tx.is_complete == False: l.addWidget(QLabel(_("Unsigned")), 3,1) if self.gui.main_window.wallet.seed : b = QPushButton("Sign transaction") - input_info = json.loads(tx_dict["input_info"]) - b.clicked.connect(lambda: self.sign_raw_transaction(tx, input_info, dialog)) + b.clicked.connect(lambda: self.sign_raw_transaction(tx, tx.inputs, dialog)) l.addWidget(b, 4, 1) else: l.addWidget(QLabel(_("Wallet is de-seeded, can't sign.")), 4,1) else: l.addWidget(QLabel(_("Signed")), 3,1) b = QPushButton("Broadcast transaction") - b.clicked.connect(lambda: self.gui.main_window.send_raw_transaction(tx, dialog)) + def broadcast(tx): + result, result_message = self.gui.main_window.wallet.sendtx( tx ) + if result: + self.gui.main_window.show_message(_("Transaction successfully sent:")+' %s' % (result_message)) + if dialog: + dialog.done(0) + else: + self.gui.main_window.show_message(_("There was a problem sending your transaction:") + '\n %s' % (result_message)) + b.clicked.connect(lambda: broadcast( tx )) l.addWidget(b,4,1) - l.addWidget( self.gui.main_window.generate_transaction_information_widget(tx), 0,0,2,3) closeButton = QPushButton(_("Close")) closeButton.clicked.connect(lambda: dialog.done(0)) l.addWidget(closeButton, 4,2) From 9bf1dac4c2513dee3c7681c8ff8f378905d33ac4 Mon Sep 17 00:00:00 2001 From: rdymac Date: Sat, 2 Nov 2013 12:40:59 +0100 Subject: [PATCH 10/17] latest wikia version, tested latest wikia version with 1.9 strings --- lib/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/version.py b/lib/version.py index 1271714f2..af0dcd96d 100644 --- a/lib/version.py +++ b/lib/version.py @@ -2,4 +2,4 @@ ELECTRUM_VERSION = "1.9" # version of the client package PROTOCOL_VERSION = '0.6' # protocol version requested SEED_VERSION = 6 # bump this every time the seed generation is modified SEED_PREFIX = '01' # the hash of the mnemonic seed must begin with this -TRANSLATION_ID = 4127 # version of the wiki page +TRANSLATION_ID = 4141 # version of the wiki page From 4714160f17166b5d42509460a5e9490d48f549c8 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sat, 2 Nov 2013 13:00:10 +0100 Subject: [PATCH 11/17] fix redeemPubKey for imported keys (fixes issue #350) --- lib/wallet.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/wallet.py b/lib/wallet.py index f9b9c7944..e3f2be42e 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -716,6 +716,8 @@ class Wallet: for sec in private_keys: pubkey = public_key_from_private_key(sec) keypairs[ pubkey ] = sec + if address in self.imported_keys.keys(): + txin['redeemPubkey'] = pubkey def add_keypairs_from_KeyID(self, tx, keypairs, password): From d8626793bc548a763741571e21131340ed2df48a Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sat, 2 Nov 2013 18:10:18 +0100 Subject: [PATCH 12/17] fix: wait_for_network --- lib/wallet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wallet.py b/lib/wallet.py index e3f2be42e..10a9c5932 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -1578,7 +1578,7 @@ class Wallet: time.sleep(0.1) def wait_for_network(): - while not self.network.interface.is_connected: + while not self.network.is_connected(): msg = "%s \n" % (_("Connecting...")) apply(callback, (msg,)) time.sleep(0.1) From c8cd187bd4441a06e80d53f0ddaeed45589f187e Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sun, 3 Nov 2013 11:03:45 +0100 Subject: [PATCH 13/17] use QStackedLayout in install wizard --- gui/qt/installwizard.py | 45 +++++++++++++++++++++------------------ gui/qt/password_dialog.py | 4 ++-- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py index 1d73faad3..1e66df7ee 100644 --- a/gui/qt/installwizard.py +++ b/gui/qt/installwizard.py @@ -24,6 +24,15 @@ class InstallWizard(QDialog): self.setWindowTitle('Electrum') self.connect(self, QtCore.SIGNAL('accept'), self.accept) + self.stack = QStackedLayout() + self.setLayout(self.stack) + + + def set_layout(self, layout): + w = QWidget() + w.setLayout(layout) + self.stack.setCurrentIndex(self.stack.addWidget(w)) + def restore_or_create(self): @@ -51,9 +60,10 @@ class InstallWizard(QDialog): grid.addWidget(b2,2,0) grid.addWidget(b3,3,0) - vbox = QVBoxLayout(self) - vbox.addLayout(grid) + vbox = QVBoxLayout() + self.set_layout(vbox) + vbox.addLayout(grid) vbox.addStretch(1) vbox.addLayout(ok_cancel_buttons(self, _('Next'))) @@ -84,9 +94,7 @@ class InstallWizard(QDialog): def seed_dialog(self, is_restore=True): - if self.layout(): QWidget().setLayout(self.layout()) - - vbox = QVBoxLayout(self) + vbox = QVBoxLayout() if is_restore: msg = _("Please enter your wallet seed.") + "\n" else: @@ -111,10 +119,10 @@ class InstallWizard(QDialog): vbox.addLayout(grid) - vbox.addStretch(1) vbox.addLayout(ok_cancel_buttons(self, _('Next'))) + self.set_layout(vbox) if not self.exec_(): return @@ -133,10 +141,10 @@ class InstallWizard(QDialog): task() self.emit(QtCore.SIGNAL('accept')) - if self.layout(): QWidget().setLayout(self.layout()) - vbox = QVBoxLayout(self) + vbox = QVBoxLayout() self.waiting_label = QLabel(msg) vbox.addWidget(self.waiting_label) + self.set_layout(vbox) t = threading.Thread(target = target) t.start() self.exec_() @@ -145,10 +153,7 @@ class InstallWizard(QDialog): def mpk_dialog(self): - if self.layout(): QWidget().setLayout(self.layout()) - - vbox = QVBoxLayout(self) - + vbox = QVBoxLayout() vbox.addWidget(QLabel(_("Please enter your master public key."))) grid = QGridLayout() @@ -171,6 +176,7 @@ class InstallWizard(QDialog): vbox.addStretch(1) vbox.addLayout(ok_cancel_buttons(self, _('Next'))) + self.set_layout(vbox) if not self.exec_(): return None, None mpk = str(mpk_e.toPlainText()).strip() @@ -180,8 +186,6 @@ class InstallWizard(QDialog): def network_dialog(self): - if self.layout(): QWidget().setLayout(self.layout()) - grid = QGridLayout() grid.setSpacing(5) @@ -206,12 +210,13 @@ class InstallWizard(QDialog): grid.addWidget(b2,2,0) #grid.addWidget(b3,3,0) - vbox = QVBoxLayout(self) + vbox = QVBoxLayout() vbox.addLayout(grid) vbox.addStretch(1) vbox.addLayout(ok_cancel_buttons(self, _('Next'))) + self.set_layout(vbox) if not self.exec_(): return @@ -227,7 +232,7 @@ class InstallWizard(QDialog): self.config.set_key('auto_cycle', False, True) return - + def show_seed(self, wallet): from seed_dialog import make_seed_dialog @@ -235,9 +240,7 @@ class InstallWizard(QDialog): vbox = make_seed_dialog(wallet.get_mnemonic(None), wallet.imported_keys) vbox.addLayout(ok_cancel_buttons(self, _("Next"))) - if self.layout(): QWidget().setLayout(self.layout()) - self.setLayout(vbox) - + self.set_layout(vbox) if not self.exec_(): exit() @@ -246,8 +249,8 @@ class InstallWizard(QDialog): msg = _("Please choose a password to encrypt your wallet keys.")+'\n'\ +_("Leave these fields empty if you want to disable encryption.") from password_dialog import make_password_dialog, run_password_dialog - if self.layout(): QWidget().setLayout(self.layout()) - make_password_dialog(self, wallet, msg) + self.set_layout( make_password_dialog(self, wallet, msg) ) + run_password_dialog(self, wallet, self) diff --git a/gui/qt/password_dialog.py b/gui/qt/password_dialog.py index dfd8e9547..dc94737f8 100644 --- a/gui/qt/password_dialog.py +++ b/gui/qt/password_dialog.py @@ -68,7 +68,7 @@ def make_password_dialog(self, wallet, msg): vbox.addStretch(1) vbox.addLayout(ok_cancel_buttons(self)) - self.setLayout(vbox) + return vbox def run_password_dialog(self, wallet, parent): @@ -119,7 +119,7 @@ class PasswordDialog(QDialog): msg = (_('Your wallet is encrypted. Use this dialog to change your password.') + ' '\ +_('To disable wallet encryption, enter an empty new password.')) \ if wallet.use_encryption else _('Your wallet keys are not encrypted') - make_password_dialog(self, wallet, msg) + self.setLayout(make_password_dialog(self, wallet, msg)) def run(self): From c2f2ec2a8c2eed7a3f848f77e8cb5cb3fa2a6bc8 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sun, 3 Nov 2013 11:06:57 +0100 Subject: [PATCH 14/17] rm debug message --- lib/network.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/network.py b/lib/network.py index 3ed5034ee..dbbd4047c 100644 --- a/lib/network.py +++ b/lib/network.py @@ -258,7 +258,6 @@ class Network(threading.Thread): def new_blockchain_height(self, blockchain_height, i): - print_error('new_blockchain_height') if self.is_connected(): h = self.heights.get(self.interface.server) if h: From 536c898b59c6c13c0014ab1d2a151856af2d7e51 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sun, 3 Nov 2013 14:14:35 +0100 Subject: [PATCH 15/17] restore from master public key with seed v4 --- electrum | 10 ++++------ gui/qt/installwizard.py | 10 +++++----- lib/commands.py | 4 ++++ lib/wallet.py | 17 +++++++++++++---- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/electrum b/electrum index ecef1f304..b7fd394e1 100755 --- a/electrum +++ b/electrum @@ -365,15 +365,13 @@ if __name__ == '__main__': elif cmd.name == 'getconfig': key = args[1] - print_msg(config.get(key)) + out = config.get(key) + print_msg(out) elif cmd.name == 'setconfig': key, value = args[1:3] - if key not in ['seed', 'seed_version', 'master_public_key', 'use_encryption']: - config.set_key(key, value, True) - print_msg(True) - else: - print_msg(False) + config.set_key(key, value, True) + print_msg(True) elif cmd.name == 'password': new_password = prompt_password('New password:') diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py index 1e66df7ee..884186cb9 100644 --- a/gui/qt/installwizard.py +++ b/gui/qt/installwizard.py @@ -166,10 +166,10 @@ class InstallWizard(QDialog): grid.addWidget(mpk_e, 0, 1) label = QLabel(_("Chain")) - grid.addWidget(label, 1, 0) + #grid.addWidget(label, 1, 0) chain_e = QTextEdit() chain_e.setMaximumHeight(100) - grid.addWidget(chain_e, 1, 1) + #grid.addWidget(chain_e, 1, 1) vbox.addLayout(grid) @@ -294,11 +294,11 @@ class InstallWizard(QDialog): elif action == 'watching': # ask for seed and gap. - K, chain = self.mpk_dialog() - if not K or not chain: + mpk = self.mpk_dialog() + if not mpk: return wallet.seed = '' - wallet.create_watching_only_wallet(chain,K) + wallet.create_watching_only_wallet(mpk) else: raise diff --git a/lib/commands.py b/lib/commands.py index b430bf1dd..dc3a9fe13 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -74,6 +74,7 @@ register_command('getconfig', 1, 1, False, False, False, 'Return a co register_command('getpubkeys', 1, 1, False, True, False, 'Return the public keys for a wallet address', 'getpubkeys ') register_command('getrawtransaction', 1, 2, True, False, False, 'Retrieve a transaction', 'getrawtransaction ') register_command('getseed', 0, 0, False, True, True, 'Print the generation seed of your wallet.') +register_command('getmpk', 0, 0, False, True, False, 'Return your wallet\'s master public key', 'getmpk') register_command('help', 0, 1, False, False, False, 'Prints this help') register_command('history', 0, 0, True, True, False, 'Returns the transaction history of your wallet') register_command('importprivkey', 1, 1, False, True, True, 'Import a private key', 'importprivkey ') @@ -214,6 +215,9 @@ class Commands: def getservers(self): return self.network.get_servers() + def getmpk(self): + return self.wallet.get_master_public_key() + def getseed(self): mnemonic = self.wallet.get_mnemonic(self.password) seed = self.wallet.get_seed(self.password) diff --git a/lib/wallet.py b/lib/wallet.py index 10a9c5932..2088c0199 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -339,7 +339,16 @@ class Wallet: self.storage.put('seed', self.seed, True) self.storage.put('seed_version', self.seed_version, True) - def create_watching_only_wallet(self, c0, K0): + def create_watching_only_wallet(self, params): + K0, c0 = params + if not K0: + return + + if not c0: + self.seed_version = 4 + self.create_old_account(K0) + return + cK0 = "" self.master_public_keys = { "m/0'/": (c0, K0, cK0), @@ -350,7 +359,8 @@ class Wallet: def create_accounts(self): if self.seed_version == 4: - self.create_old_account() + mpk = OldAccount.mpk_from_seed(self.seed) + self.create_old_account(mpk) else: # create default account self.create_master_keys('1') @@ -513,8 +523,7 @@ class Wallet: self.set_label(k, name) - def create_old_account(self): - mpk = OldAccount.mpk_from_seed(self.seed) + def create_old_account(self, mpk): self.storage.put('master_public_key', mpk, True) self.accounts[0] = OldAccount({'mpk':mpk, 0:[], 1:[]}) self.save_accounts() From 8fe6f4208fb7495a378c0fc41a00b1bbf0e070e6 Mon Sep 17 00:00:00 2001 From: ecdsa Date: Mon, 4 Nov 2013 10:04:21 +0100 Subject: [PATCH 16/17] fix init_lite --- gui/qt/main_window.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index 94cc5fdbf..dd0a947b4 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -219,6 +219,7 @@ class ElectrumWindow(QMainWindow): self.config.set_key('lite_mode', False, True) sys.exit(0) self.mini = None + self.show() return actuator = lite_window.MiniActuator(self) From 051c882a3f5288b467fbee1950ec391204a245c4 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Mon, 4 Nov 2013 10:16:48 +0100 Subject: [PATCH 17/17] use returned amount with ! shortcut --- gui/qt/main_window.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index dd0a947b4..f1b465a73 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -793,7 +793,7 @@ class ElectrumWindow(QMainWindow): c, u = self.wallet.get_account_balance(self.current_account) inputs, total, fee = self.wallet.choose_tx_inputs_from_account( c + u, 0, self.current_account) fee = self.wallet.estimated_fee(inputs) - amount = c + u - fee + amount = total - fee self.amount_e.setText( self.format_amount(amount) ) self.fee_e.setText( self.format_amount( fee ) ) return