commit 088d8e841554ab02fbc0285fcadb420f08343f72
parent e4946cf26ee8be2c1f997ca813740963194d48f3
Author: ThomasV <thomasv@gitorious>
Date: Tue, 2 Jun 2015 11:36:06 +0200
show request status
Diffstat:
5 files changed, 39 insertions(+), 18 deletions(-)
diff --git a/electrum b/electrum
@@ -191,6 +191,9 @@ def run_cmdline(config):
cmd.requires_password = False
cmd.requires_wallet = False
+ if cmdname == 'listrequests' and config.get('status'):
+ cmd.requires_network = True
+
# arguments passed to function
args = map(lambda x: config.get(x), cmd.params)
# options
diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
@@ -79,7 +79,7 @@ class StatusBarButton(QPushButton):
apply(self.func,())
-from electrum.paymentrequest import PR_UNPAID, PR_PAID, PR_EXPIRED
+from electrum.paymentrequest import PR_UNPAID, PR_PAID, PR_UNKNOWN, PR_EXPIRED
from electrum.paymentrequest import PaymentRequest, InvoiceStore, get_payment_request, make_payment_request
pr_icons = {
@@ -814,15 +814,9 @@ class ElectrumWindow(QMainWindow):
date = format_time(timestamp)
account = self.wallet.get_account_name(self.wallet.get_account_from_address(address))
amount_str = self.format_amount(amount) if amount else ""
- if amount:
- paid = amount <= self.wallet.get_addr_received(address)
- status = PR_PAID if paid else PR_UNPAID
- if status == PR_UNPAID and expiration is not None and time.time() > timestamp + expiration:
- status = PR_EXPIRED
- else:
- status = ''
+ status = self.wallet.get_request_status(address, amount, timestamp, expiration)
item = QTreeWidgetItem([date, account, address, message, amount_str, pr_tooltips.get(status,'')])
- if status is not '':
+ if status is not PR_UNKNOWN:
item.setIcon(5, QIcon(pr_icons.get(status)))
self.receive_list.addTopLevelItem(item)
diff --git a/lib/commands.py b/lib/commands.py
@@ -506,14 +506,24 @@ class Commands:
"""Decrypt a message encrypted with a public key."""
return self.wallet.decrypt_message(pubkey, encrypted, self.password)
- def _format_request(self, v):
+ def _format_request(self, v, show_status):
+ from paymentrequest import PR_PAID, PR_UNPAID, PR_UNKNOWN, PR_EXPIRED
+ pr_str = {
+ PR_UNKNOWN: 'Unknown',
+ PR_UNPAID: 'Pending',
+ PR_PAID: 'Paid',
+ PR_EXPIRED: 'Expired',
+ }
addr = v.get('address')
+ amount = v.get('amount')
+ timestamp = v.get('time')
+ expiration = v.get('expiration')
out = {
'address': addr,
- 'amount': format_satoshis(v.get('amount')),
- 'time': v.get('time'),
+ 'amount': format_satoshis(amount),
+ 'time': timestamp,
'reason': self.wallet.get_label(addr)[0],
- 'expiration': v.get('expiration'),
+ 'expiration': expiration,
}
if v.get('path'):
url = 'file://' + v.get('path')
@@ -523,12 +533,15 @@ class Commands:
url = url.replace(a, b)
URI = 'bitcoin:?r=' + url
out['url'] = URI
+ if show_status:
+ status = self.wallet.get_request_status(addr, amount, timestamp, expiration)
+ out['status'] = pr_str[status]
return out
@command('w')
- def listrequests(self):
- """List the payment requests you made"""
- return map(self._format_request, self.wallet.receive_requests.values())
+ def listrequests(self, status=False):
+ """List the payment requests you made, and their status"""
+ return map(lambda x: self._format_request(x, status), self.wallet.receive_requests.values())
@command('w')
def addrequest(self, amount, reason='', expiration=60*60):
@@ -589,7 +602,7 @@ command_options = {
'account': (None, "--account", "Account"),
'reason': (None, "--reason", "Description of the request"),
'expiration': (None, "--expiration", "Time in seconds"),
- 'request_dir': (None, "--request_dir", "Directory where request are written"),
+ 'status': (None, "--status", "Show status"),
}
diff --git a/lib/paymentrequest.py b/lib/paymentrequest.py
@@ -50,7 +50,7 @@ ca_list, ca_keyID = x509.load_certificates(ca_path)
# status of payment requests
PR_UNPAID = 0
PR_EXPIRED = 1
-PR_SENT = 2 # sent but not propagated
+PR_UNKNOWN = 2 # sent but not propagated
PR_PAID = 3 # send and propagated
PR_ERROR = 4 # could not parse
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -1248,6 +1248,17 @@ class Abstract_Wallet(object):
def get_payment_request(self, key):
return self.receive_requests.get(key)
+ def get_request_status(self, address, amount, timestamp, expiration):
+ from paymentrequest import PR_PAID, PR_UNPAID, PR_UNKNOWN, PR_EXPIRED
+ if amount:
+ paid = amount <= self.get_addr_received(address)
+ status = PR_PAID if paid else PR_UNPAID
+ if status == PR_UNPAID and expiration is not None and time.time() > timestamp + expiration:
+ status = PR_EXPIRED
+ else:
+ status = PR_UNKNOWN
+ return status
+
def save_payment_request(self, config, addr, amount, message, expiration):
#if addr in self.receive_requests:
# self.receive_requests[addr]['amount'] = amount