X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=gui%2Fqt%2Fmain_window.py;h=874b8e28c3956402c7dd3710e2a02f0a340b2990;hb=81d1e67253c8ca581e821a6cd9e5ee1502fffd08;hp=dccf9feca2751deb13b81f269ddd3ced0428c181;hpb=a89abee9690b011031b20c39dc1d48a4b9ec1ceb;p=electrum-nvc.git diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index dccf9fe..874b8e2 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -75,7 +75,7 @@ PR_ERROR = 4 # could not parse from electrum import ELECTRUM_VERSION import re -from util import * +from util import MyTreeWidget, HelpButton, EnterButton, line_dialog, text_dialog, ok_cancel_buttons, close_button, WaitingDialog def format_status(x): @@ -286,12 +286,20 @@ class ElectrumWindow(QMainWindow): import installwizard wallet_folder = os.path.dirname(self.wallet.storage.path) - filename = unicode( QFileDialog.getSaveFileName(self, _('Enter a new file name'), wallet_folder) ) + i = 1 + while True: + filename = "wallet_%d"%i + if filename in os.listdir(wallet_folder): + i += 1 + else: + break + + filename = line_dialog(self, _('New Wallet'), _('Enter file name') + ':', _('OK'), filename) if not filename: return - filename = os.path.join(wallet_folder, filename) - storage = WalletStorage({'wallet_path': filename}) + full_path = os.path.join(wallet_folder, filename) + storage = WalletStorage({'wallet_path': full_path}) if storage.file_exists: QMessageBox.critical(None, "Error", _("File exists")) return @@ -352,6 +360,7 @@ class ElectrumWindow(QMainWindow): raw_transaction_menu.addAction(_("&From file"), self.do_process_from_file) raw_transaction_menu.addAction(_("&From text"), self.do_process_from_text) raw_transaction_menu.addAction(_("&From the blockchain"), self.do_process_from_txid) + raw_transaction_menu.addAction(_("&From QR code"), self.read_tx_from_qrcode) self.raw_transaction_menu = raw_transaction_menu help_menu = menubar.addMenu(_("&Help")) @@ -748,7 +757,7 @@ class ElectrumWindow(QMainWindow): def new_receive_address(self): domain = self.wallet.get_account_addresses(self.current_account, include_change=False) for addr in domain: - if not self.wallet.address_is_old(addr) and addr not in self.receive_requests.keys(): + if not self.wallet.history.get(addr) and addr not in self.receive_requests.keys(): break else: if isinstance(self.wallet, Imported_Wallet): @@ -765,7 +774,7 @@ class ElectrumWindow(QMainWindow): self.receive_requests = self.wallet.storage.get('receive_requests',{}) domain = self.wallet.get_account_addresses(self.current_account, include_change=False) for addr in domain: - if not self.wallet.address_is_old(addr) and addr not in self.receive_requests.keys(): + if not self.wallet.history.get(addr) and addr not in self.receive_requests.keys(): break else: addr = '' @@ -991,20 +1000,20 @@ class ElectrumWindow(QMainWindow): QMessageBox.warning(self, _('Error'), _('No outputs'), _('OK')) return - for addr, x in outputs: + for type, addr, amount in outputs: if addr is None: QMessageBox.warning(self, _('Error'), _('Bitcoin Address is None'), _('OK')) return - if addr.startswith('OP_RETURN:'): + if type == 'op_return': continue - if not bitcoin.is_address(addr): + if type == 'address' and not bitcoin.is_address(addr): QMessageBox.warning(self, _('Error'), _('Invalid Bitcoin Address'), _('OK')) return - if x is None: + if amount is None: QMessageBox.warning(self, _('Error'), _('Invalid Amount'), _('OK')) return - amount = sum(map(lambda x:x[1], outputs)) + amount = sum(map(lambda x:x[2], outputs)) fee = self.fee_e.get_amount() if fee is None: @@ -1013,7 +1022,7 @@ class ElectrumWindow(QMainWindow): confirm_amount = self.config.get('confirm_amount', 100000000) if amount >= confirm_amount: - o = '\n'.join(map(lambda x:x[0], outputs)) + o = '\n'.join(map(lambda x:x[1], outputs)) if not self.question(_("send %(amount)s to %(address)s?")%{ 'amount' : self.format_amount(amount) + ' '+ self.base_unit(), 'address' : o}): return @@ -1060,6 +1069,7 @@ class ElectrumWindow(QMainWindow): self.wallet.add_keypairs(tx, keypairs, password) self.wallet.sign_transaction(tx, keypairs, password) except Exception as e: + traceback.print_exc(file=sys.stdout) tx.error = str(e) return tx @@ -1775,7 +1785,7 @@ class ElectrumWindow(QMainWindow): self.wallet.create_pending_account(name, password) self.update_address_tab() - self.tabs.setCurrentIndex(2) + self.tabs.setCurrentIndex(3) @@ -1987,7 +1997,7 @@ class ElectrumWindow(QMainWindow): pubkey_e = QLineEdit() if address: - pubkey = self.wallet.getpubkeys(address)[0] + pubkey = self.wallet.get_public_keys(address)[0] pubkey_e.setText(pubkey) layout.addWidget(QLabel(_('Public key')), 2, 0) layout.addWidget(pubkey_e, 2, 1) @@ -2082,6 +2092,21 @@ class ElectrumWindow(QMainWindow): QMessageBox.critical(None, _("Unable to parse transaction"), _("Electrum was unable to parse your transaction")) + def read_tx_from_qrcode(self): + data = run_hook('scan_qr_hook') + if not data: + return + # transactions are binary, but qrcode seems to return utf8... + z = data.decode('utf8') + s = '' + for b in z: + s += chr(ord(b)) + data = s.encode('hex') + tx = self.tx_from_text(data) + if not tx: + return + self.show_transaction(tx) + def read_tx_from_file(self): fileName = self.getOpenFileName(_("Select your transaction file"), "*.txn") @@ -2136,12 +2161,12 @@ class ElectrumWindow(QMainWindow): try: for position, row in enumerate(csvReader): address = row[0] - if not is_valid(address): + if not is_address(address): errors.append((position, address)) continue amount = Decimal(row[1]) amount = int(100000000*amount) - outputs.append((address, amount)) + outputs.append(('address', address, amount)) except (ValueError, IOError, os.error), reason: QMessageBox.critical(None, _("Unable to read file or no transaction found"), _("Electrum was unable to open your transaction file") + "\n" + str(reason)) return