store contacts and invoices in wallet file. fix #1482
This commit is contained in:
@@ -11,7 +11,6 @@ import electrum
|
||||
from electrum.bitcoin import TYPE_ADDRESS
|
||||
from electrum import WalletStorage, Wallet
|
||||
from electrum_gui.kivy.i18n import _
|
||||
from electrum.contacts import Contacts
|
||||
from electrum.paymentrequest import InvoiceStore
|
||||
from electrum.util import profiler, InvalidPassword
|
||||
from electrum.plugins import run_hook
|
||||
@@ -201,9 +200,6 @@ class ElectrumWindow(App):
|
||||
self.daemon = self.gui_object.daemon
|
||||
self.fx = self.daemon.fx
|
||||
|
||||
self.contacts = Contacts(self.electrum_config)
|
||||
self.invoices = InvoiceStore(self.electrum_config)
|
||||
|
||||
# create triggers so as to minimize updation a max of 2 times a sec
|
||||
self._trigger_update_wallet =\
|
||||
Clock.create_trigger(self.update_wallet, .5)
|
||||
@@ -217,11 +213,11 @@ class ElectrumWindow(App):
|
||||
return os.path.basename(self.wallet.storage.path) if self.wallet else ' '
|
||||
|
||||
def on_pr(self, pr):
|
||||
if pr.verify(self.contacts):
|
||||
key = self.invoices.add(pr)
|
||||
if pr.verify(self.wallet.contacts):
|
||||
key = self.wallet.invoices.add(pr)
|
||||
if self.invoices_screen:
|
||||
self.invoices_screen.update()
|
||||
status = self.invoices.get_status(key)
|
||||
status = self.wallet.invoices.get_status(key)
|
||||
if status == PR_PAID:
|
||||
self.show_error("invoice already paid")
|
||||
self.send_screen.do_clear()
|
||||
@@ -731,7 +727,7 @@ class ElectrumWindow(App):
|
||||
self.show_info(txid)
|
||||
if ok and pr:
|
||||
pr.set_paid(tx.hash())
|
||||
self.invoices.save()
|
||||
self.wallet.invoices.save()
|
||||
self.update_tab('invoices')
|
||||
|
||||
if self.network and self.network.is_connected():
|
||||
|
||||
@@ -224,7 +224,7 @@ class SendScreen(CScreen):
|
||||
req['amount'] = amount
|
||||
pr = make_unsigned_request(req).SerializeToString()
|
||||
pr = PaymentRequest(pr)
|
||||
self.app.invoices.add(pr)
|
||||
self.app.wallet.invoices.add(pr)
|
||||
self.app.update_tab('invoices')
|
||||
self.app.show_info(_("Invoice saved"))
|
||||
if pr.is_pr():
|
||||
@@ -449,7 +449,7 @@ class InvoicesScreen(CScreen):
|
||||
self.menu_actions = [('Pay', self.do_pay), ('Details', self.do_view), ('Delete', self.do_delete)]
|
||||
invoices_list = self.screen.ids.invoices_container
|
||||
invoices_list.clear_widgets()
|
||||
_list = self.app.invoices.sorted_list()
|
||||
_list = self.app.wallet.invoices.sorted_list()
|
||||
for pr in _list:
|
||||
ci = self.get_card(pr)
|
||||
invoices_list.add_widget(ci)
|
||||
@@ -458,19 +458,19 @@ class InvoicesScreen(CScreen):
|
||||
invoices_list.add_widget(EmptyLabel(text=msg))
|
||||
|
||||
def do_pay(self, obj):
|
||||
pr = self.app.invoices.get(obj.key)
|
||||
pr = self.app.wallet.invoices.get(obj.key)
|
||||
self.app.on_pr(pr)
|
||||
|
||||
def do_view(self, obj):
|
||||
pr = self.app.invoices.get(obj.key)
|
||||
pr.verify(self.app.contacts)
|
||||
pr = self.app.wallet.invoices.get(obj.key)
|
||||
pr.verify(self.app.wallet.contacts)
|
||||
self.app.show_pr_details(pr.get_dict(), obj.status, True)
|
||||
|
||||
def do_delete(self, obj):
|
||||
from dialogs.question import Question
|
||||
def cb(result):
|
||||
if result:
|
||||
self.app.invoices.remove(obj.key)
|
||||
self.app.wallet.invoices.remove(obj.key)
|
||||
self.app.update_tab('invoices')
|
||||
d = Question(_('Delete invoice?'), cb)
|
||||
d.open()
|
||||
|
||||
@@ -39,8 +39,6 @@ import PyQt4.QtCore as QtCore
|
||||
from electrum.i18n import _, set_language
|
||||
from electrum.plugins import run_hook
|
||||
from electrum import SimpleConfig, Wallet, WalletStorage
|
||||
from electrum.paymentrequest import InvoiceStore
|
||||
from electrum.contacts import Contacts
|
||||
from electrum.synchronizer import Synchronizer
|
||||
from electrum.verifier import SPV
|
||||
from electrum.util import DebugMem, UserCancelled, InvalidPassword
|
||||
@@ -89,9 +87,6 @@ class ElectrumGui:
|
||||
self.app = QApplication(sys.argv)
|
||||
self.app.installEventFilter(self.efilter)
|
||||
self.timer = Timer()
|
||||
# shared objects
|
||||
self.invoices = InvoiceStore(self.config)
|
||||
self.contacts = Contacts(self.config)
|
||||
# init tray
|
||||
self.dark_icon = self.config.get("dark_icon", False)
|
||||
self.tray = QSystemTrayIcon(self.tray_icon(), None)
|
||||
|
||||
@@ -51,22 +51,29 @@ class ContactList(MyTreeWidget):
|
||||
self.parent.contacts.pop(prior)
|
||||
self.parent.set_contact(unicode(item.text(0)), unicode(item.text(1)))
|
||||
|
||||
def import_contacts(self):
|
||||
wallet_folder = self.parent.get_wallet_folder()
|
||||
filename = unicode(QFileDialog.getOpenFileName(self.parent, "Select your wallet file", wallet_folder))
|
||||
if not filename:
|
||||
return
|
||||
self.parent.contacts.import_file(filename)
|
||||
self.on_update()
|
||||
|
||||
def create_menu(self, position):
|
||||
menu = QMenu()
|
||||
selected = self.selectedItems()
|
||||
if not selected:
|
||||
menu.addAction(_("New contact"), lambda: self.parent.new_contact_dialog())
|
||||
menu.addAction(_("Import file"), lambda: self.parent.import_contacts())
|
||||
else:
|
||||
names = [unicode(item.text(0)) for item in selected]
|
||||
keys = [unicode(item.text(1)) 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])
|
||||
|
||||
menu.addAction(_("Copy %s")%column_title, lambda: self.parent.app.clipboard().setText(column_data))
|
||||
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(keys))
|
||||
menu.addAction(_("Delete"), lambda: self.parent.delete_contacts(keys))
|
||||
URLs = [block_explorer_URL(self.config, 'addr', key) for key in filter(is_address, keys)]
|
||||
|
||||
@@ -58,17 +58,23 @@ class InvoiceList(MyTreeWidget):
|
||||
self.setVisible(len(inv_list))
|
||||
self.parent.invoices_label.setVisible(len(inv_list))
|
||||
|
||||
def create_menu(self, position):
|
||||
item = self.itemAt(position)
|
||||
if not item:
|
||||
def import_invoices(self):
|
||||
wallet_folder = self.parent.get_wallet_folder()
|
||||
filename = unicode(QFileDialog.getOpenFileName(self.parent, "Select your wallet file", wallet_folder))
|
||||
if not filename:
|
||||
return
|
||||
self.parent.invoices.import_file(filename)
|
||||
self.on_update()
|
||||
|
||||
def create_menu(self, position):
|
||||
menu = QMenu()
|
||||
item = self.itemAt(position)
|
||||
key = str(item.data(0, 32).toString())
|
||||
column = self.currentColumn()
|
||||
column = self.currentColumn()
|
||||
column_title = self.headerItem().text(column)
|
||||
column_data = item.text(column)
|
||||
pr = self.parent.invoices.get(key)
|
||||
status = self.parent.invoices.get_status(key)
|
||||
menu = QMenu()
|
||||
if column_data:
|
||||
menu.addAction(_("Copy %s")%column_title, lambda: self.parent.app.clipboard().setText(column_data))
|
||||
menu.addAction(_("Details"), lambda: self.parent.show_invoice(key))
|
||||
|
||||
@@ -47,7 +47,7 @@ from electrum.plugins import run_hook
|
||||
from electrum.i18n import _
|
||||
from electrum.util import (block_explorer, block_explorer_info, format_time,
|
||||
block_explorer_URL, format_satoshis, PrintError,
|
||||
format_satoshis_plain, NotEnoughFunds, StoreDict,
|
||||
format_satoshis_plain, NotEnoughFunds,
|
||||
UserCancelled)
|
||||
from electrum import Transaction, mnemonic
|
||||
from electrum import util, bitcoin, commands, coinchooser
|
||||
@@ -99,8 +99,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
self.config = config = gui_object.config
|
||||
self.network = gui_object.daemon.network
|
||||
self.fx = gui_object.daemon.fx
|
||||
self.invoices = gui_object.invoices
|
||||
self.contacts = gui_object.contacts
|
||||
self.invoices = wallet.invoices
|
||||
self.contacts = wallet.contacts
|
||||
self.tray = gui_object.tray
|
||||
self.app = gui_object.app
|
||||
self.cleaned_up = False
|
||||
@@ -434,6 +434,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
|
||||
wallet_menu = menubar.addMenu(_("&Wallet"))
|
||||
wallet_menu.addAction(_("&New contact"), self.new_contact_dialog)
|
||||
wallet_menu.addAction(_("Import invoices"), lambda: self.invoice_list.import_invoices())
|
||||
wallet_menu.addAction(_("Import contacts"), lambda: self.contact_list.import_contacts())
|
||||
wallet_menu.addSeparator()
|
||||
|
||||
self.password_menu = wallet_menu.addAction(_("&Password"), self.change_password_dialog)
|
||||
|
||||
@@ -2,7 +2,7 @@ from decimal import Decimal
|
||||
_ = lambda x:x
|
||||
#from i18n import _
|
||||
from electrum import WalletStorage, Wallet
|
||||
from electrum.util import format_satoshis, set_verbosity, StoreDict
|
||||
from electrum.util import format_satoshis, set_verbosity
|
||||
from electrum.bitcoin import is_valid, COIN, TYPE_ADDRESS
|
||||
from electrum.network import filter_protocol
|
||||
import sys, getpass, datetime
|
||||
@@ -35,7 +35,7 @@ class ElectrumGui:
|
||||
|
||||
self.wallet = Wallet(storage)
|
||||
self.wallet.start_threads(self.network)
|
||||
self.contacts = StoreDict(self.config, 'contacts')
|
||||
self.contacts = self.wallet.contacts
|
||||
|
||||
self.network.register_callback(self.on_network, ['updated', 'banner'])
|
||||
self.commands = [_("[h] - displays this help text"), \
|
||||
|
||||
@@ -4,7 +4,6 @@ from decimal import Decimal
|
||||
import getpass
|
||||
|
||||
from electrum.util import format_satoshis, set_verbosity
|
||||
from electrum.util import StoreDict
|
||||
from electrum.bitcoin import is_valid, COIN, TYPE_ADDRESS
|
||||
from electrum import Wallet, WalletStorage
|
||||
|
||||
@@ -27,7 +26,7 @@ class ElectrumGui:
|
||||
storage.decrypt(password)
|
||||
self.wallet = Wallet(storage)
|
||||
self.wallet.start_threads(self.network)
|
||||
self.contacts = StoreDict(self.config, 'contacts')
|
||||
self.contacts = self.wallet.contacts
|
||||
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
self.encoding = locale.getpreferredencoding()
|
||||
|
||||
Reference in New Issue
Block a user