commit 20bbe85bcecb454a4647b675066d6accea37bc78
parent 8e89c0c971645c11e205a163b38e4b35fa3e85de
Author: SomberNight <somber.night@protonmail.com>
Date: Sat, 7 Dec 2019 05:58:58 +0100
receive requests: encode lightning invoices as uppercase -> smaller QRs
By encoding bolt11 invoices as uppercase text in QR codes,
we can use the alphanumeric mode, which results in non-negligibly smaller QR codes.
Diffstat:
4 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/electrum/gui/kivy/main_window.py b/electrum/gui/kivy/main_window.py
@@ -431,9 +431,8 @@ class ElectrumWindow(App):
def show_request(self, is_lightning, key):
from .uix.dialogs.request_dialog import RequestDialog
request = self.wallet.get_request(key)
- status = request['status']
data = request['invoice'] if is_lightning else request['URI']
- self.request_popup = RequestDialog('Request', data, key)
+ self.request_popup = RequestDialog('Request', data, key, is_lightning=is_lightning)
self.request_popup.set_status(request['status'])
self.request_popup.open()
diff --git a/electrum/gui/kivy/uix/dialogs/addresses.py b/electrum/gui/kivy/uix/dialogs/addresses.py
@@ -1,3 +1,5 @@
+from typing import TYPE_CHECKING
+
from kivy.app import App
from kivy.factory import Factory
from kivy.properties import ObjectProperty
@@ -7,6 +9,10 @@ from kivy.uix.popup import Popup
from electrum.gui.kivy.i18n import _
+if TYPE_CHECKING:
+ from ...main_window import ElectrumWindow
+
+
Builder.load_string('''
<AddressLabel@Label>
text_size: self.width, None
@@ -184,7 +190,7 @@ class AddressesDialog(Factory.Popup):
def __init__(self, app):
Factory.Popup.__init__(self)
- self.app = app
+ self.app = app # type: ElectrumWindow
def get_card(self, addr, balance, is_used, label):
ci = {}
diff --git a/electrum/gui/kivy/uix/dialogs/request_dialog.py b/electrum/gui/kivy/uix/dialogs/request_dialog.py
@@ -66,16 +66,22 @@ Builder.load_string('''
class RequestDialog(Factory.Popup):
- def __init__(self, title, data, key):
+ def __init__(self, title, data, key, *, is_lightning=False):
self.status = PR_UNKNOWN
Factory.Popup.__init__(self)
self.app = App.get_running_app()
self.title = title
self.data = data
self.key = key
+ self.is_lightning = is_lightning
def on_open(self):
- self.ids.qr.set_data(self.data)
+ data = self.data
+ if self.is_lightning:
+ # encode lightning invoices as uppercase so QR encoding can use
+ # alphanumeric mode; resulting in smaller QR codes
+ data = data.upper()
+ self.ids.qr.set_data(data)
def set_status(self, status):
self.status = status
diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py
@@ -60,7 +60,7 @@ from electrum.util import (format_time, format_satoshis, format_fee_satoshis,
decimal_point_to_base_unit_name,
UnknownBaseUnit, DECIMAL_POINT_DEFAULT, UserFacingException,
get_new_wallet_name, send_exception_to_crash_reporter,
- InvalidBitcoinURI)
+ InvalidBitcoinURI, maybe_extract_bolt11_invoice)
from electrum.util import PR_TYPE_ONCHAIN, PR_TYPE_LN
from electrum.transaction import (Transaction, PartialTxInput,
PartialTransaction, PartialTxOutput)
@@ -1171,6 +1171,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
def update_receive_qr(self):
uri = str(self.receive_address_e.text())
+ if maybe_extract_bolt11_invoice(uri):
+ # encode lightning invoices as uppercase so QR encoding can use
+ # alphanumeric mode; resulting in smaller QR codes
+ uri = uri.upper()
self.receive_qr.setData(uri)
if self.qr_window and self.qr_window.isVisible():
self.qr_window.qrw.setData(uri)