commit a6c65b8997c2407502edbe5cc9d818722e1db2cd
parent 2c1fb1e37ce0e82c768befd2c3d52cf07cc75c5e
Author: ThomasV <thomasv@gitorious>
Date: Tue, 21 Jul 2015 12:26:37 +0200
change internal format of requests
Diffstat:
4 files changed, 25 insertions(+), 24 deletions(-)
diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
@@ -681,7 +681,7 @@ class ElectrumWindow(QMainWindow):
return
addr = str(item.text(2))
req = self.wallet.receive_requests[addr]
- expires = _('Never') if req.get('expiration') is None else util.age(req['timestamp'] + req['expiration'])
+ expires = _('Never') if req.get('exp') is None else util.age(req['time'] + req['exp'])
amount = req['amount']
message = self.wallet.labels.get(addr, '')
self.receive_address_e.setText(addr)
@@ -703,14 +703,14 @@ class ElectrumWindow(QMainWindow):
message = self.wallet.labels.get(addr, '')
amount = req['amount']
URI = util.create_URI(addr, amount, message)
- if req.get('id') and req.get('sig'):
+ if req.get('time'):
+ URI += "&time=%d"%req.get('time')
+ if req.get('exp'):
+ URI += "&exp=%d"%req.get('exp')
+ if req.get('name') and req.get('sig'):
sig = req.get('sig').decode('hex')
sig = bitcoin.base_encode(sig, base=58)
- URI += "&id=" + req['id'] + "&sig="+sig
- if req.get('timestamp'):
- URI += "×tamp=%d"%req.get('timestamp')
- if req.get('expiration'):
- URI += "&expiration=%d"%req.get('expiration')
+ URI += "&name=" + req['name'] + "&sig="+sig
return str(URI)
def receive_list_menu(self, position):
@@ -748,7 +748,7 @@ class ElectrumWindow(QMainWindow):
return
pr, requestor = paymentrequest.make_request(self.config, req, alias, alias_privkey)
if requestor:
- req['id'] = requestor
+ req['name'] = requestor
req['sig'] = pr.signature.encode('hex')
self.wallet.add_payment_request(req, self.config)
@@ -870,14 +870,14 @@ class ElectrumWindow(QMainWindow):
address = req['address']
if address not in domain:
continue
- timestamp = req['timestamp']
+ timestamp = req.get('time', 0)
amount = req.get('amount')
- expiration = req.get('expiration', None)
+ expiration = req.get('exp', None)
message = req.get('memo', '')
date = format_time(timestamp)
status = req.get('status')
signature = req.get('sig')
- requestor = req.get('id', '')
+ requestor = req.get('name', '')
amount_str = self.format_amount(amount) if amount else ""
account = ''
item = QTreeWidgetItem([date, account, address, '', message, amount_str, pr_tooltips.get(status,'')])
@@ -1348,10 +1348,10 @@ class ElectrumWindow(QMainWindow):
r = out.get('r')
sig = out.get('sig')
- _id = out.get('id')
- if r or (_id and sig):
+ name = out.get('name')
+ if r or (name and sig):
def get_payment_request_thread():
- if _id and sig:
+ if name and sig:
from electrum import paymentrequest
pr = paymentrequest.serialize_request(out).SerializeToString()
self.payment_request = paymentrequest.PaymentRequest(pr)
diff --git a/lib/paymentrequest.py b/lib/paymentrequest.py
@@ -290,11 +290,11 @@ class PaymentRequest:
def make_unsigned_request(req):
from transaction import Transaction
addr = req['address']
- time = req['timestamp']
+ time = req['time']
amount = req['amount']
if amount is None:
amount = 0
- expires = req['expiration']
+ expires = req['exp']
memo = req['memo']
script = Transaction.pay_script('address', addr).decode('hex')
outputs = [(script, amount)]
@@ -340,7 +340,7 @@ def sign_request_with_x509(pr, key_path, cert_path):
def serialize_request(req):
pr = make_unsigned_request(req)
signature = req.get('sig')
- requestor = req.get('id')
+ requestor = req.get('name')
if requestor and signature:
pr.signature = signature.decode('hex')
pr.pki_type = 'dnssec+btc'
diff --git a/lib/util.py b/lib/util.py
@@ -278,9 +278,10 @@ def parse_URI(uri):
if 'message' in out:
out['message'] = out['message'].decode('utf8')
out['memo'] = out['message']
- if 'timestamp' in out:
- out['timestamp'] = int(out['timestamp'])
- out['expiration'] = int(out['expiration'])
+ if 'time' in out:
+ out['time'] = int(out['time'])
+ if 'exp' in out:
+ out['exp'] = int(out['exp'])
if 'sig' in out:
out['sig'] = bitcoin.base_decode(out['sig'], None, base=58).encode('hex')
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -1242,8 +1242,8 @@ class Abstract_Wallet(object):
r = self.receive_requests[key]
address = r['address']
amount = r.get('amount')
- timestamp = r.get('timestamp', 0)
- expiration = r.get('expiration')
+ timestamp = r.get('time', 0)
+ expiration = r.get('exp')
if amount:
if self.up_to_date:
paid = amount <= self.get_addr_received(address)
@@ -1259,7 +1259,7 @@ class Abstract_Wallet(object):
def make_payment_request(self, addr, amount, message, expiration):
timestamp = int(time.time())
_id = Hash(addr + "%d"%timestamp).encode('hex')[0:10]
- r = {'timestamp':timestamp, 'amount':amount, 'expiration':expiration, 'address':addr, 'memo':message, 'id':_id}
+ r = {'time':timestamp, 'amount':amount, 'exp':expiration, 'address':addr, 'memo':message, 'id':_id}
return r
def add_payment_request(self, req, config):
@@ -1305,7 +1305,7 @@ class Abstract_Wallet(object):
return True
def get_sorted_requests(self, config):
- return sorted(map(lambda x: self.get_payment_request(x, config), self.receive_requests.keys()), key=itemgetter('timestamp'))
+ return sorted(map(lambda x: self.get_payment_request(x, config), self.receive_requests.keys()), key=lambda x: x.get('time', 0))