X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=gui%2Fqt%2Fmain_window.py;h=1715139ba315aad4d208ad0da5bdce42a08a26da;hb=f9dad74e13b3979322e25d9e37b56c553662f4e0;hp=f8b5336c0ca682c1f66f8e7eb02e2583bc5e5bc9;hpb=2da9a02fb382684fb130399f6e634d2e19d66692;p=electrum-nvc.git diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index f8b5336..1715139 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -40,6 +40,7 @@ from electrum import Transaction from electrum import mnemonic from electrum import util, bitcoin, commands, Interface, Wallet from electrum import SimpleConfig, Wallet, WalletStorage +from electrum import Imported_Wallet from amountedit import AmountEdit, BTCAmountEdit, MyLineEdit from network_dialog import NetworkDialog @@ -443,9 +444,14 @@ class ElectrumWindow(QMainWindow): def base_unit(self): - assert self.decimal_point in [5,8] - return "BTC" if self.decimal_point == 8 else "mBTC" - + assert self.decimal_point in [2, 5, 8] + if self.decimal_point == 2: + return 'bits' + if self.decimal_point == 5: + return 'mBTC' + if self.decimal_point == 8: + return 'BTC' + raise Exception('Unknown base unit') def update_status(self): if self.network is None or not self.network.is_running(): @@ -681,7 +687,7 @@ class ElectrumWindow(QMainWindow): self.save_request_button.clicked.connect(self.save_payment_request) grid.addWidget(self.save_request_button, 3, 1) clear_button = QPushButton(_('New')) - clear_button.clicked.connect(self.clear_receive_tab) + clear_button.clicked.connect(self.new_receive_address) grid.addWidget(clear_button, 3, 2) grid.setRowStretch(4, 1) @@ -739,14 +745,30 @@ class ElectrumWindow(QMainWindow): self.wallet.storage.put('receive_requests', self.receive_requests) self.update_receive_tab() + 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.history.get(addr) and addr not in self.receive_requests.keys(): + break + else: + if isinstance(self.wallet, Imported_Wallet): + self.show_message(_('No more addresses in your wallet.')) + return + if not self.question(_("Warning: The next address will not be recovered automatically if you restore your wallet from seed; you may need to add it manually.\n\nThis occurs because you have too many unused addresses in your wallet. To avoid this situation, use the existing addresses first.\n\nCreate anyway?")): + return + addr = self.wallet.create_new_address(self.current_account, False) + self.receive_address_e.setText(addr) + self.receive_message_e.setText('') + self.receive_amount_e.setAmount(None) + def clear_receive_tab(self): 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 = "" + addr = '' self.receive_address_e.setText(addr) self.receive_message_e.setText('') self.receive_amount_e.setAmount(None) @@ -876,16 +898,21 @@ class ElectrumWindow(QMainWindow): amount = self.amount_e.get_amount() fee = self.fee_e.get_amount() + outputs = self.payto_e.get_outputs() + + if not is_fee: + fee = None - if not is_fee: fee = None if amount is None: self.fee_e.setAmount(None) - return - # assume that there will be 2 outputs (one for change) - inputs, total, fee = self.wallet.choose_tx_inputs(amount, fee, 2, coins = self.get_coins()) - if not is_fee: - self.fee_e.setAmount(fee) - if inputs: + not_enough_funds = False + else: + inputs, total, fee = self.wallet.choose_tx_inputs(amount, fee, len(outputs), coins = self.get_coins()) + not_enough_funds = len(inputs) == 0 + if not is_fee: + self.fee_e.setAmount(fee) + + if not not_enough_funds: palette = QPalette() palette.setColor(self.amount_e.foregroundRole(), QColor('black')) text = "" @@ -964,15 +991,20 @@ class ElectrumWindow(QMainWindow): QMessageBox.warning(self, _('Error'), _('No outputs'), _('OK')) return - for addr, x in outputs: - if addr is None or not bitcoin.is_address(addr): + for type, addr, amount in outputs: + if addr is None: + QMessageBox.warning(self, _('Error'), _('Bitcoin Address is None'), _('OK')) + return + if type == 'op_return': + continue + 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: @@ -981,7 +1013,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 @@ -1021,11 +1053,14 @@ class ElectrumWindow(QMainWindow): # sign the tx def sign_thread(): + if self.wallet.is_watching_only(): + return tx keypairs = {} try: 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 @@ -1491,24 +1526,6 @@ class ElectrumWindow(QMainWindow): menu.exec_(self.invoices_list.viewport().mapToGlobal(position)) - def update_address_item(self, item): - item.setFont(0, QFont(MONOSPACE_FONT)) - address = str(item.data(0,0).toString()) - label = self.wallet.labels.get(address,'') - item.setData(1,0,label) - item.setData(0,32, True) # is editable - - run_hook('update_address_item', address, item) - - if not self.wallet.is_mine(address): return - - c, u = self.wallet.get_addr_balance(address) - balance = self.format_amount(c + u) - item.setData(2,0,balance) - - if address in self.wallet.frozen_addresses: - item.setBackgroundColor(0, QColor('lightblue')) - def update_address_tab(self): l = self.address_list @@ -1551,27 +1568,22 @@ class ElectrumWindow(QMainWindow): used_item = QTreeWidgetItem( [ _("Used"), '', '', '', ''] ) used_flag = False - is_red = False - gap = 0 - - for address in account.get_addresses(is_change): - + addr_list = account.get_addresses(is_change) + for address in addr_list: num, is_used = self.wallet.is_used(address) - if num == 0: - gap += 1 - if gap > self.wallet.gap_limit: - is_red = True - else: - gap = 0 - - item = QTreeWidgetItem( [ address, '', '', "%d"%num] ) - self.update_address_item(item) - if is_red: - item.setBackgroundColor(1, QColor('red')) - + label = self.wallet.labels.get(address,'') + c, u = self.wallet.get_addr_balance(address) + balance = self.format_amount(c + u) + item = QTreeWidgetItem( [ address, label, balance, "%d"%num] ) + item.setFont(0, QFont(MONOSPACE_FONT)) + item.setData(0, 32, True) # label can be edited + if address in self.wallet.frozen_addresses: + item.setBackgroundColor(0, QColor('lightblue')) + if self.wallet.is_beyond_limit(address, account, is_change): + item.setBackgroundColor(0, QColor('red')) if is_used: if not used_flag: - seq_item.insertChild(0,used_item) + seq_item.insertChild(0, used_item) used_flag = True used_item.addChild(item) else: @@ -1600,7 +1612,6 @@ class ElectrumWindow(QMainWindow): l.setCurrentItem(l.topLevelItem(0)) - def create_console_tab(self): from console import Console self.console = console = Console() @@ -1765,7 +1776,7 @@ class ElectrumWindow(QMainWindow): self.wallet.create_pending_account(name, password) self.update_address_tab() - self.tabs.setCurrentIndex(2) + self.tabs.setCurrentIndex(3) @@ -1977,7 +1988,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) @@ -2053,7 +2064,7 @@ class ElectrumWindow(QMainWindow): if is_hex: try: - return Transaction(txt) + return Transaction.deserialize(txt) except: traceback.print_exc(file=sys.stdout) QMessageBox.critical(None, _("Unable to parse transaction"), _("Electrum was unable to parse your transaction")) @@ -2062,7 +2073,7 @@ class ElectrumWindow(QMainWindow): try: tx_dict = json.loads(str(txt)) assert "hex" in tx_dict.keys() - tx = Transaction(tx_dict["hex"]) + tx = Transaction.deserialize(tx_dict["hex"]) #if tx_dict.has_key("input_info"): # input_info = json.loads(tx_dict['input_info']) # tx.add_input_info(input_info) @@ -2113,7 +2124,7 @@ class ElectrumWindow(QMainWindow): if ok and txid: r = self.network.synchronous_get([ ('blockchain.transaction.get',[str(txid)]) ])[0] if r: - tx = transaction.Transaction(r) + tx = transaction.Transaction.deserialize(r) if tx: self.show_transaction(tx) else: @@ -2126,12 +2137,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 @@ -2483,7 +2494,7 @@ class ElectrumWindow(QMainWindow): if not self.config.is_modifiable('fee_per_kb'): for w in [fee_e, fee_label]: w.setEnabled(False) - units = ['BTC', 'mBTC'] + units = ['BTC', 'mBTC', 'bits'] unit_label = QLabel(_('Base unit') + ':') grid.addWidget(unit_label, 3, 0) unit_combo = QComboBox() @@ -2554,7 +2565,14 @@ class ElectrumWindow(QMainWindow): unit_result = units[unit_combo.currentIndex()] if self.base_unit() != unit_result: - self.decimal_point = 8 if unit_result == 'BTC' else 5 + if unit_result == 'BTC': + self.decimal_point = 8 + elif unit_result == 'mBTC': + self.decimal_point = 5 + elif unit_result == 'bits': + self.decimal_point = 2 + else: + raise Exception('Unknown base unit') self.config.set_key('decimal_point', self.decimal_point, True) self.update_history_tab() self.update_status()