Skip to content

Commit

Permalink
change internal format of requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasV committed Jul 21, 2015
1 parent 2c1fb1e commit a6c65b8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
28 changes: 14 additions & 14 deletions gui/qt/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ def receive_item_changed(self, item):
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)
Expand All @@ -703,14 +703,14 @@ def get_request_URI(self, addr):
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 += "&timestamp=%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):
Expand Down Expand Up @@ -748,7 +748,7 @@ def sign_payment_request(self, addr):
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)

Expand Down Expand Up @@ -870,14 +870,14 @@ def update_receive_tab(self):
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,'')])
Expand Down Expand Up @@ -1348,10 +1348,10 @@ def pay_to_URI(self, URI):

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)
Expand Down
6 changes: 3 additions & 3 deletions lib/paymentrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,11 @@ def send_ack(self, raw_tx, refund_addr):
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)]
Expand Down Expand Up @@ -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'
Expand Down
7 changes: 4 additions & 3 deletions lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
8 changes: 4 additions & 4 deletions lib/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,8 @@ def get_request_status(self, key):
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)
Expand All @@ -1259,7 +1259,7 @@ def get_request_status(self, key):
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):
Expand Down Expand Up @@ -1305,7 +1305,7 @@ def remove_payment_request(self, addr, config):
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))



Expand Down

0 comments on commit a6c65b8

Please sign in to comment.