commit acbd434f76a407dfcaa7493a138054ee726898e8
parent 074872afbc5b33ee837c1be2dde577e4583890f6
Author: ThomasV <thomasv@gitorious>
Date: Wed, 22 Jul 2015 09:06:03 +0200
cleanup request signing
Diffstat:
4 files changed, 25 insertions(+), 19 deletions(-)
diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
@@ -730,7 +730,6 @@ class ElectrumWindow(QMainWindow):
menu.exec_(self.receive_list.viewport().mapToGlobal(position))
def sign_payment_request(self, addr):
- req = self.wallet.receive_requests.get(addr)
alias = self.config.get('alias')
alias_privkey = None
if alias and self.alias_info:
@@ -741,7 +740,7 @@ class ElectrumWindow(QMainWindow):
password = self.password_dialog(msg)
if password:
try:
- alias_privkey = self.wallet.get_private_key(alias_addr, password)[0]
+ self.wallet.sign_payment_request(addr, alias, alias_addr, password)
except Exception as e:
QMessageBox.warning(self, _('Error'), str(e), _('OK'))
return
@@ -749,11 +748,7 @@ class ElectrumWindow(QMainWindow):
return
else:
return
- pr, requestor = paymentrequest.make_request(self.config, req, alias, alias_privkey)
- if requestor:
- req['name'] = requestor
- req['sig'] = pr.signature.encode('hex')
- self.wallet.add_payment_request(req, self.config)
+
def save_payment_request(self):
addr = str(self.receive_address_e.text())
diff --git a/lib/commands.py b/lib/commands.py
@@ -578,6 +578,13 @@ class Commands:
self.wallet.add_payment_request(req, self.config)
return self._format_request(req)
+ @command('wp')
+ def signrequest(self, key):
+ "Sign payment request with an OpenAlias"
+ alias = self.config.get('alias')
+ alias_addr = self.contacts.resolve(alias)['address']
+ self.wallet.sign_payment_request(key, alias, alias_addr, self.password)
+
@command('w')
def rmrequest(self, key):
"""Remove a payment request"""
diff --git a/lib/paymentrequest.py b/lib/paymentrequest.py
@@ -348,21 +348,13 @@ def serialize_request(req):
return pr
-def make_request(config, req, alias=None, alias_privkey=None):
+def make_request(config, req):
pr = make_unsigned_request(req)
key_path = config.get('ssl_privkey')
cert_path = config.get('ssl_chain')
- requestor = None
-
if key_path and cert_path:
sign_request_with_x509(pr, key_path, cert_path)
- requestor = 'x'
-
- elif alias and alias_privkey:
- requestor = alias
- sign_request_with_alias(pr, alias, alias_privkey)
-
- return pr, requestor
+ return pr
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -41,6 +41,8 @@ import bitcoin
from synchronizer import WalletSynchronizer
from mnemonic import Mnemonic
+import paymentrequest
+
# internal ID for imported account
@@ -1262,8 +1264,18 @@ class Abstract_Wallet(object):
r = {'time':timestamp, 'amount':amount, 'exp':expiration, 'address':addr, 'memo':message, 'id':_id}
return r
+ def sign_payment_request(self, key, alias, alias_addr, password):
+ req = self.receive_requests.get(key)
+ alias_privkey = self.get_private_key(alias_addr, password)[0]
+ pr = paymentrequest.make_unsigned_request(req)
+ paymentrequest.sign_request_with_alias(pr, alias, alias_privkey)
+ req['name'] = pr.pki_data
+ req['sig'] = pr.signature.encode('hex')
+ self.receive_requests[key] = req
+ self.storage.put('payment_requests', self.receive_requests)
+
def add_payment_request(self, req, config):
- import paymentrequest, shutil, os
+ import shutil, os
addr = req['address']
amount = req.get('amount')
message = req.get('memo')
@@ -1280,7 +1292,7 @@ class Abstract_Wallet(object):
src = os.path.join(os.path.dirname(__file__), 'www', 'index.html')
shutil.copy(src, index)
key = req.get('id', addr)
- pr, requestor = paymentrequest.make_request(config, req)
+ pr = paymentrequest.make_request(config, req)
path = os.path.join(rdir, key + '.bip70')
with open(path, 'w') as f:
f.write(pr.SerializeToString())