Browse Source

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.
hard-fail-on-bad-server-string
SomberNight 5 years ago
parent
commit
20bbe85bce
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 3
      electrum/gui/kivy/main_window.py
  2. 8
      electrum/gui/kivy/uix/dialogs/addresses.py
  3. 10
      electrum/gui/kivy/uix/dialogs/request_dialog.py
  4. 6
      electrum/gui/qt/main_window.py

3
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()

8
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 = {}

10
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

6
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)

Loading…
Cancel
Save