electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 28da62f51b260c6680b15ea19bf5d080684a4891
parent 96d3c36e4ae0a46ade0b171ffa77a26edac1c42f
Author: ThomasV <thomasv@electrum.org>
Date:   Thu,  5 Sep 2019 14:43:27 +0200

add PayServer settings to settings_dialog

Diffstat:
Melectrum/daemon.py | 8++++----
Melectrum/gui/qt/settings_dialog.py | 96++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
Melectrum/wallet.py | 8++++----
3 files changed, 81 insertions(+), 31 deletions(-)

diff --git a/electrum/daemon.py b/electrum/daemon.py @@ -185,9 +185,9 @@ class HttpServer(Logger): await self.pending[key].set() async def run(self): - host = self.config.get('http_host', 'localhost') - port = self.config.get('http_port') - root = self.config.get('http_root', '/r') + host = self.config.get('payserver_host', 'localhost') + port = self.config.get('payserver_port') + root = self.config.get('payserver_root', '/r') ssl_keyfile = self.config.get('ssl_keyfile') ssl_certfile = self.config.get('ssl_certfile') if ssl_keyfile and ssl_certfile: @@ -289,7 +289,7 @@ class Daemon(Logger): if listen_jsonrpc: jobs.append(self.start_jsonrpc(config, fd)) # request server - if self.config.get('http_port'): + if self.config.get('payserver_port'): self.http_server = HttpServer(self) jobs.append(self.http_server.run()) # server-side watchtower diff --git a/electrum/gui/qt/settings_dialog.py b/electrum/gui/qt/settings_dialog.py @@ -181,29 +181,38 @@ class SettingsDialog(WindowModalDialog): self.alias_e.editingFinished.connect(self.on_alias_edit) oa_widgets.append((alias_label, self.alias_e)) - # SSL certificate - msg = ' '.join([ - _('SSL certificate used to sign payment requests.'), - _('Use setconfig to set ssl_chain and ssl_privkey.'), - ]) - if self.config.get('ssl_keyfile') and self.config.get('ssl_certfile'): - try: - SSL_identity = paymentrequest.check_ssl_config(self.config) - SSL_error = None - except BaseException as e: - SSL_identity = "error" - SSL_error = repr(e) - else: - SSL_identity = "" - SSL_error = None - SSL_id_label = HelpLabel(_('SSL certificate') + ':', msg) - SSL_id_e = QLineEdit(SSL_identity) - SSL_id_e.setStyleSheet((ColorScheme.RED if SSL_error else ColorScheme.GREEN).as_stylesheet(True) if SSL_identity else '') - if SSL_error: - SSL_id_e.setToolTip(SSL_error) - SSL_id_e.setReadOnly(True) - server_widgets.append((SSL_id_label, SSL_id_e)) - + # PayServer + ssl_cert = self.config.get('ssl_certfile') + ssl_cert_label = HelpLabel(_('SSL cert file') + ':', 'certificate file, with intermediate certificates if needed') + self.ssl_cert_e = QPushButton(ssl_cert) + self.ssl_cert_e.clicked.connect(self.select_ssl_certfile) + server_widgets.append((ssl_cert_label, self.ssl_cert_e)) + + ssl_privkey = self.config.get('ssl_keyfile') + ssl_privkey_label = HelpLabel(_('SSL key file') + ':', '') + self.ssl_privkey_e = QPushButton(ssl_privkey) + self.ssl_cert_e.clicked.connect(self.select_ssl_certfile) + server_widgets.append((ssl_privkey_label, self.ssl_privkey_e)) + + ssl_domain_label = HelpLabel(_('SSL domain') + ':', '') + self.ssl_domain_e = QLineEdit('') + self.ssl_domain_e.setReadOnly(True) + server_widgets.append((ssl_domain_label, self.ssl_domain_e)) + + payserver_host = self.config.get('payserver_host', 'localhost') + payserver_host_label = HelpLabel(_('Hostname') + ':', 'must match your ssl domain') + self.payserver_host_e = QLineEdit(payserver_host) + self.payserver_host_e.editingFinished.connect(self.on_payserver_host) + server_widgets.append((payserver_host_label, self.payserver_host_e)) + + payserver_port = self.config.get('payserver_port') + payserver_port_label = HelpLabel(_('Port') + ':', msg) + self.payserver_port_e = QLineEdit(str(payserver_port)) + self.payserver_port_e.editingFinished.connect(self.on_payserver_port) + server_widgets.append((payserver_port_label, self.payserver_port_e)) + self.check_ssl_config() + + # units units = base_units_list msg = (_('Base unit of your wallet.') + '\n1 BTC = 1000 mBTC. 1 mBTC = 1000 bits. 1 bit = 100 sat.\n' @@ -498,3 +507,44 @@ class SettingsDialog(WindowModalDialog): self.config.set_key('alias', alias, True) if alias: self.window.fetch_alias() + + def select_ssl_certfile(self, b): + name = self.config.get('ssl_certfile', '') + filename, __ = QFileDialog.getOpenFileName(self, "Select your SSL certificate file", name) + if filename: + self.config.set_key('ssl_certfile', filename) + self.ssl_cert_e.setText(filename) + self.check_ssl_config() + + def select_ssl_privkey(self, b): + name = self.config.get('ssl_privkey', '') + filename, __ = QFileDialog.getOpenFileName(self, "Select your SSL private key file", name) + if filename: + self.config.set_key('ssl_privkey', filename) + self.ssl_cert_e.setText(filename) + self.check_ssl_config() + + def check_ssl_config(self): + if self.config.get('ssl_keyfile') and self.config.get('ssl_certfile'): + try: + SSL_identity = paymentrequest.check_ssl_config(self.config) + SSL_error = None + except BaseException as e: + SSL_identity = "error" + SSL_error = repr(e) + else: + SSL_identity = "" + SSL_error = None + self.ssl_domain_e.setText(SSL_identity) + s = (ColorScheme.RED if SSL_error else ColorScheme.GREEN).as_stylesheet(True) if SSL_identity else '' + self.ssl_domain_e.setStyleSheet(s) + if SSL_error: + self.ssl_domain_e.setToolTip(SSL_error) + + def on_payserver_host(self): + hostname = str(self.payserver_host_e.text()) + self.config.set_key('payserver_host', hostname, True) + + def on_payserver_port(self): + port = int(self.payserver_port_e.text()) + self.config.set_key('payserver_port', port, True) diff --git a/electrum/wallet.py b/electrum/wallet.py @@ -1329,10 +1329,10 @@ class Abstract_Wallet(AddressSynchronizer): req = self.lnworker.get_request(key) if not req: return - if config.get('http_port'): - host = config.get('http_host', 'localhost') - port = config.get('http_port') - root = config.get('http_root', '/r') + if config.get('payserver_port'): + host = config.get('payserver_host', 'localhost') + port = config.get('payserver_port') + root = config.get('payserver_root', '/r') use_ssl = bool(config.get('ssl_keyfile')) protocol = 'https' if use_ssl else 'http' base = '%s://%s:%d'%(protocol, host, port)