Browse Source

show request status

master
ThomasV 11 years ago
parent
commit
088d8e8415
  1. 3
      electrum
  2. 12
      gui/qt/main_window.py
  3. 29
      lib/commands.py
  4. 2
      lib/paymentrequest.py
  5. 11
      lib/wallet.py

3
electrum

@ -191,6 +191,9 @@ def run_cmdline(config):
cmd.requires_password = False cmd.requires_password = False
cmd.requires_wallet = False cmd.requires_wallet = False
if cmdname == 'listrequests' and config.get('status'):
cmd.requires_network = True
# arguments passed to function # arguments passed to function
args = map(lambda x: config.get(x), cmd.params) args = map(lambda x: config.get(x), cmd.params)
# options # options

12
gui/qt/main_window.py

@ -79,7 +79,7 @@ class StatusBarButton(QPushButton):
apply(self.func,()) 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 from electrum.paymentrequest import PaymentRequest, InvoiceStore, get_payment_request, make_payment_request
pr_icons = { pr_icons = {
@ -814,15 +814,9 @@ class ElectrumWindow(QMainWindow):
date = format_time(timestamp) date = format_time(timestamp)
account = self.wallet.get_account_name(self.wallet.get_account_from_address(address)) account = self.wallet.get_account_name(self.wallet.get_account_from_address(address))
amount_str = self.format_amount(amount) if amount else "" amount_str = self.format_amount(amount) if amount else ""
if amount: status = self.wallet.get_request_status(address, amount, timestamp, expiration)
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 = ''
item = QTreeWidgetItem([date, account, address, message, amount_str, pr_tooltips.get(status,'')]) 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))) item.setIcon(5, QIcon(pr_icons.get(status)))
self.receive_list.addTopLevelItem(item) self.receive_list.addTopLevelItem(item)

29
lib/commands.py

@ -506,14 +506,24 @@ class Commands:
"""Decrypt a message encrypted with a public key.""" """Decrypt a message encrypted with a public key."""
return self.wallet.decrypt_message(pubkey, encrypted, self.password) 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') addr = v.get('address')
amount = v.get('amount')
timestamp = v.get('time')
expiration = v.get('expiration')
out = { out = {
'address': addr, 'address': addr,
'amount': format_satoshis(v.get('amount')), 'amount': format_satoshis(amount),
'time': v.get('time'), 'time': timestamp,
'reason': self.wallet.get_label(addr)[0], 'reason': self.wallet.get_label(addr)[0],
'expiration': v.get('expiration'), 'expiration': expiration,
} }
if v.get('path'): if v.get('path'):
url = 'file://' + v.get('path') url = 'file://' + v.get('path')
@ -523,12 +533,15 @@ class Commands:
url = url.replace(a, b) url = url.replace(a, b)
URI = 'bitcoin:?r=' + url URI = 'bitcoin:?r=' + url
out['url'] = URI out['url'] = URI
if show_status:
status = self.wallet.get_request_status(addr, amount, timestamp, expiration)
out['status'] = pr_str[status]
return out return out
@command('w') @command('w')
def listrequests(self): def listrequests(self, status=False):
"""List the payment requests you made""" """List the payment requests you made, and their status"""
return map(self._format_request, self.wallet.receive_requests.values()) return map(lambda x: self._format_request(x, status), self.wallet.receive_requests.values())
@command('w') @command('w')
def addrequest(self, amount, reason='', expiration=60*60): def addrequest(self, amount, reason='', expiration=60*60):
@ -589,7 +602,7 @@ command_options = {
'account': (None, "--account", "Account"), 'account': (None, "--account", "Account"),
'reason': (None, "--reason", "Description of the request"), 'reason': (None, "--reason", "Description of the request"),
'expiration': (None, "--expiration", "Time in seconds"), 'expiration': (None, "--expiration", "Time in seconds"),
'request_dir': (None, "--request_dir", "Directory where request are written"), 'status': (None, "--status", "Show status"),
} }

2
lib/paymentrequest.py

@ -50,7 +50,7 @@ ca_list, ca_keyID = x509.load_certificates(ca_path)
# status of payment requests # status of payment requests
PR_UNPAID = 0 PR_UNPAID = 0
PR_EXPIRED = 1 PR_EXPIRED = 1
PR_SENT = 2 # sent but not propagated PR_UNKNOWN = 2 # sent but not propagated
PR_PAID = 3 # send and propagated PR_PAID = 3 # send and propagated
PR_ERROR = 4 # could not parse PR_ERROR = 4 # could not parse

11
lib/wallet.py

@ -1248,6 +1248,17 @@ class Abstract_Wallet(object):
def get_payment_request(self, key): def get_payment_request(self, key):
return self.receive_requests.get(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): def save_payment_request(self, config, addr, amount, message, expiration):
#if addr in self.receive_requests: #if addr in self.receive_requests:
# self.receive_requests[addr]['amount'] = amount # self.receive_requests[addr]['amount'] = amount

Loading…
Cancel
Save