electrum

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

commit 2259b741f6d3531837874139a19b4a8cdd8c0d8f
parent 1a8b12360baa6fb5c148340c24be1159808bf378
Author: ThomasV <thomasv@electrum.org>
Date:   Sat, 28 May 2016 16:56:18 +0200

use address as key in contacts

Diffstat:
Mgui/qt/contact_list.py | 20++++++++++----------
Mgui/qt/main_window.py | 17+++--------------
Mlib/contacts.py | 7+++++++
3 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/gui/qt/contact_list.py b/gui/qt/contact_list.py @@ -36,13 +36,13 @@ from util import MyTreeWidget, pr_tooltips, pr_icons class ContactList(MyTreeWidget): def __init__(self, parent): - MyTreeWidget.__init__(self, parent, self.create_menu, [_('Name'), _('Value'), _('Type')], 1, [0, 1]) + MyTreeWidget.__init__(self, parent, self.create_menu, [_('Name'), _('Type'), _('Value')], 0, [0]) self.setSelectionMode(QAbstractItemView.ExtendedSelection) self.setSortingEnabled(True) def on_permit_edit(self, item, column): # openalias items shouldn't be editable - return item.text(2) != "openalias" + return item.text(1) != "openalias" def on_edited(self, item, column, prior): if column == 0: # Remove old contact if renamed @@ -55,9 +55,9 @@ class ContactList(MyTreeWidget): if not selected: menu.addAction(_("New contact"), lambda: self.parent.new_contact_dialog()) else: - labels = [unicode(item.text(0)) for item in selected] - addrs = [unicode(item.text(1)) for item in selected] - types = [unicode(item.text(2)) for item in selected] + names = [unicode(item.text(0)) for item in selected] + types = [unicode(item.text(1)) for item in selected] + keys = [unicode(item.text(2)) for item in selected] column = self.currentColumn() column_title = self.headerItem().text(column) column_data = '\n'.join([unicode(item.text(column)) for item in selected]) @@ -66,10 +66,10 @@ class ContactList(MyTreeWidget): if column in self.editable_columns: menu.addAction(_("Edit %s")%column_title, lambda: self.editItem(item, column)) - menu.addAction(_("Pay to"), lambda: self.parent.payto_contacts(labels)) - menu.addAction(_("Delete"), lambda: self.parent.delete_contacts(labels)) + menu.addAction(_("Pay to"), lambda: self.parent.payto_contacts(keys)) + menu.addAction(_("Delete"), lambda: self.parent.delete_contacts(keys)) URLs = [] - for (addr, _type) in zip(addrs, types): + for (addr, _type) in zip(keys, types): if _type == 'address': URLs.append(block_explorer_URL(self.config, 'addr', addr)) if URLs: @@ -84,8 +84,8 @@ class ContactList(MyTreeWidget): current_key = item.data(0, Qt.UserRole).toString() if item else None self.clear() for key in sorted(self.parent.contacts.keys()): - _type, value = self.parent.contacts[key] - item = QTreeWidgetItem([key, value, _type]) + _type, name = self.parent.contacts[key] + item = QTreeWidgetItem([name, _type, key]) item.setData(0, Qt.UserRole, key) self.addTopLevelItem(item) if key == current_key: diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -269,7 +269,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): wallet.thread = TaskThread(self, self.on_error) self.wallet = wallet self.update_recently_visited(wallet.storage.path) - self.import_old_contacts() # address used to create a dummy transaction and estimate transaction fee self.accounts_expanded = self.wallet.storage.get('accounts_expanded',{}) self.current_account = self.wallet.storage.get("current_account", None) @@ -320,16 +319,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): ]) self.show_warning(msg, title=_('Information')) - def import_old_contacts(self): - # backward compatibility: import contacts - old_contacts = self.wallet.storage.get('contacts', []) - if old_contacts: - for k in set(old_contacts): - l = self.wallet.labels.get(k) - if bitcoin.is_address(k) and l: - self.contacts[l] = ('address', k) - self.wallet.storage.put('contacts', None) - def open_wallet(self): wallet_folder = self.get_wallet_folder() filename = unicode(QFileDialog.getOpenFileName(self, "Select your wallet file", wallet_folder)) @@ -1106,8 +1095,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): self.from_list.addTopLevelItem(QTreeWidgetItem( [format(item), self.format_amount(item['value']) ])) def get_contact_payto(self, key): - _type, value = self.contacts.get(key) - return key + ' <' + value + '>' if _type == 'address' else key + _type, label = self.contacts.get(key) + return label + ' <' + key + '>' if _type == 'address' else key def update_completions(self): l = [self.get_contact_payto(key) for key in self.contacts.keys()] @@ -1486,7 +1475,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): self.show_error(_('Invalid Address')) self.contact_list.update() # Displays original unchanged value return False - self.contacts[label] = ('address', address) + self.contacts[address] = ('address', label) self.contact_list.update() self.history_list.update() self.update_completions() diff --git a/lib/contacts.py b/lib/contacts.py @@ -35,6 +35,13 @@ class Contacts(StoreDict): def __init__(self, config): StoreDict.__init__(self, config, 'contacts') + # backward compatibility + for k, v in self.items(): + _type, n = v + if _type == 'address' and bitcoin.is_address(n): + self.pop(k) + self[n] = ('address', k) + def resolve(self, k): if bitcoin.is_address(k):