electrum

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

commit 6185f94de413fbbe3de0c0ffffd52a8692dacee2
parent 8e90d6a4e53dfa567599b8974f6f1790212a466f
Author: ThomasV <thomasv@electrum.org>
Date:   Wed, 15 Mar 2017 15:32:14 +0100

archive paid invoices in the history tab

Diffstat:
Mgui/kivy/main_window.py | 2+-
Mgui/qt/history_list.py | 7+++++++
Mgui/qt/invoice_list.py | 3+--
Mgui/qt/main_window.py | 29++++++++++-------------------
Mlib/paymentrequest.py | 12+++++++++---
5 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py @@ -729,7 +729,7 @@ class ElectrumWindow(App): if self.send_screen: self.send_screen.do_clear() if pr: - pr.set_paid(tx.txid()) + self.wallet.invoices.set_paid(pr, tx.txid()) self.wallet.invoices.save() self.update_tab('invoices') else: diff --git a/gui/qt/history_list.py b/gui/qt/history_list.py @@ -79,6 +79,7 @@ class HistoryList(MyTreeWidget): for h_item in h: tx_hash, height, conf, timestamp, value, balance = h_item status, status_str = self.wallet.get_tx_status(tx_hash, height, conf, timestamp) + has_invoice = self.wallet.invoices.paid.get(tx_hash) icon = QIcon(":icons/" + TX_ICONS[status]) v_str = self.parent.format_amount(value, True, whitespaces=True) balance_str = self.parent.format_amount(balance, whitespaces=True) @@ -91,6 +92,8 @@ class HistoryList(MyTreeWidget): entry.append(text) item = QTreeWidgetItem(entry) item.setIcon(0, icon) + if has_invoice: + item.setIcon(3, QIcon(":icons/seal")) for i in range(len(entry)): if i>3: item.setTextAlignment(i, Qt.AlignRight) @@ -144,6 +147,8 @@ class HistoryList(MyTreeWidget): tx = self.wallet.transactions.get(tx_hash) is_relevant, is_mine, v, fee = self.wallet.get_wallet_delta(tx) is_unconfirmed = height <= 0 + pr_key = self.wallet.invoices.paid.get(tx_hash) + menu = QMenu() menu.addAction(_("Copy %s")%column_title, lambda: self.parent.app.clipboard().setText(column_data)) @@ -159,6 +164,8 @@ class HistoryList(MyTreeWidget): child_tx = self.wallet.cpfp(tx, 0) if child_tx: menu.addAction(_("Child pays for parent"), lambda: self.parent.cpfp(tx, child_tx)) + if pr_key: + menu.addAction(QIcon(":icons/seal"), _("View invoice"), lambda: self.parent.show_invoice(pr_key)) if tx_URL: menu.addAction(_("View on block explorer"), lambda: webbrowser.open(tx_URL)) menu.exec_(self.viewport().mapToGlobal(position)) diff --git a/gui/qt/invoice_list.py b/gui/qt/invoice_list.py @@ -29,7 +29,6 @@ from electrum.i18n import _ from electrum.util import block_explorer_URL, format_satoshis, format_time from electrum.plugins import run_hook - class InvoiceList(MyTreeWidget): filter_columns = [0, 1, 2, 3] # Date, Requestor, Description, Amount @@ -40,7 +39,7 @@ class InvoiceList(MyTreeWidget): self.setColumnWidth(1, 200) def on_update(self): - inv_list = self.parent.invoices.sorted_list() + inv_list = self.parent.invoices.unpaid_invoices() self.clear() for pr in inv_list: key = pr.get_id() diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -1383,7 +1383,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): return False, _("Payment request has expired") status, msg = self.network.broadcast(tx) if pr and status is True: - pr.set_paid(tx.txid()) + self.invoices.set_paid(pr, tx.txid()) self.invoices.save() self.payment_request = None refund_address = self.wallet.get_receiving_addresses()[0] @@ -1621,27 +1621,18 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): grid = QGridLayout() grid.addWidget(QLabel(_("Requestor") + ':'), 0, 0) grid.addWidget(QLabel(pr.get_requestor()), 0, 1) - grid.addWidget(QLabel(_("Expires") + ':'), 1, 0) - grid.addWidget(QLabel(format_time(pr.get_expiration_date())), 1, 1) - grid.addWidget(QLabel(_("Memo") + ':'), 2, 0) - grid.addWidget(QLabel(pr.get_memo()), 2, 1) - grid.addWidget(QLabel(_("Signature") + ':'), 3, 0) - grid.addWidget(QLabel(pr.get_verify_status()), 3, 1) - grid.addWidget(QLabel(_("Payment URL") + ':'), 4, 0) - grid.addWidget(QLabel(pr.payment_url), 4, 1) - grid.addWidget(QLabel(_("Outputs") + ':'), 5, 0) - outputs_str = '\n'.join(map(lambda x: x[1] + ' ' + self.format_amount(x[2])+ self.base_unit(), pr.get_outputs())) - grid.addWidget(QLabel(outputs_str), 5, 1) - if pr.tx: - grid.addWidget(QLabel(_("Transaction ID") + ':'), 6, 0) - l = QLineEdit(pr.tx) - l.setReadOnly(True) - grid.addWidget(l, 6, 1) + grid.addWidget(QLabel(_("Amount") + ':'), 1, 0) + outputs_str = '\n'.join(map(lambda x: self.format_amount(x[2])+ self.base_unit() + ' @ ' + x[1], pr.get_outputs())) + grid.addWidget(QLabel(outputs_str), 1, 1) + grid.addWidget(QLabel(_("Expires") + ':'), 2, 0) + grid.addWidget(QLabel(format_time(pr.get_expiration_date())), 2, 1) + grid.addWidget(QLabel(_("Memo") + ':'), 3, 0) + grid.addWidget(QLabel(pr.get_memo()), 3, 1) + grid.addWidget(QLabel(_("Signature") + ':'), 4, 0) + grid.addWidget(QLabel(pr.get_verify_status()), 4, 1) vbox.addLayout(grid) vbox.addLayout(Buttons(CloseButton(d))) d.exec_() - return - def do_pay_invoice(self, key): pr = self.invoices.get(key) diff --git a/lib/paymentrequest.py b/lib/paymentrequest.py @@ -298,9 +298,6 @@ class PaymentRequest: print "PaymentACK message received: %s" % paymntack.memo return True, paymntack.memo - def set_paid(self, tx_hash): - self.tx = tx_hash - def make_unsigned_request(req): from transaction import Transaction @@ -460,9 +457,14 @@ class InvoiceStore(object): def __init__(self, storage): self.storage = storage self.invoices = {} + self.paid = {} d = self.storage.get('invoices', {}) self.load(d) + def set_paid(self, pr, txid): + pr.tx = txid + self.paid[txid] = pr.get_id() + def load(self, d): for k, v in d.items(): try: @@ -470,6 +472,8 @@ class InvoiceStore(object): pr.tx = v.get('txid') pr.requestor = v.get('requestor') self.invoices[k] = pr + if pr.tx: + self.paid[pr.tx] = k except: continue @@ -517,3 +521,5 @@ class InvoiceStore(object): # sort return self.invoices.values() + def unpaid_invoices(self): + return [ self.invoices[k] for k in filter(lambda x: self.get_status(x)!=PR_PAID, self.invoices.keys())]