Skip to content

Commit f10ae24

Browse files
committed
qt: initial support for bolt12 offers
1 parent 469d784 commit f10ae24

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

electrum/gui/icons/bolt12.png

3.54 KB
Loading

electrum/gui/qt/invoice_list.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ def update(self):
111111
for idx, item in enumerate(self.wallet.get_unpaid_invoices()):
112112
key = item.get_id()
113113
if item.is_lightning():
114-
icon_name = 'lightning.png'
114+
if item.lightning_invoice:
115+
icon_name = 'lightning.png'
116+
else:
117+
icon_name = 'bolt12.png'
115118
else:
116119
icon_name = 'bitcoin.png'
117120
if item.bip70:

electrum/gui/qt/main_window.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import electrum
5151
from electrum.gui import messages
5252
from electrum import (keystore, constants, util, bitcoin, commands,
53-
paymentrequest, lnutil)
53+
paymentrequest, lnutil, bolt12)
5454
from electrum.bitcoin import COIN, is_address, DummyAddress
5555
from electrum.plugin import run_hook
5656
from electrum.i18n import _
@@ -1704,7 +1704,13 @@ def do_export():
17041704

17051705
def show_lightning_invoice(self, invoice: Invoice):
17061706
from electrum.util import format_short_id
1707-
lnaddr = lndecode(invoice.lightning_invoice)
1707+
if bolt12_invoice_tlv := invoice.bolt12_invoice_tlv():
1708+
bolt12_inv = bolt12.decode_invoice(bolt12_invoice_tlv)
1709+
lnaddr = bolt12.to_lnaddr(bolt12_inv)
1710+
elif invoice.lightning_invoice:
1711+
lnaddr = lndecode(invoice.lightning_invoice) # FIXME: assumes BOLT11, should be abstracted by Invoice
1712+
else:
1713+
raise Exception()
17081714
d = WindowModalDialog(self, _("Lightning Invoice"))
17091715
vbox = QVBoxLayout(d)
17101716
grid = QGridLayout()

electrum/gui/qt/send_tab.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,8 @@ def update_fields(self):
449449
lock_recipient = pi.type in [PaymentIdentifierType.LNURL, PaymentIdentifierType.LNURLW,
450450
PaymentIdentifierType.LNURLP, PaymentIdentifierType.LNADDR,
451451
PaymentIdentifierType.OPENALIAS, PaymentIdentifierType.BIP70,
452-
PaymentIdentifierType.BIP21, PaymentIdentifierType.BOLT11] and not pi.need_resolve()
452+
PaymentIdentifierType.BIP21, PaymentIdentifierType.BOLT11,
453+
PaymentIdentifierType.BOLT12_OFFER] and not pi.need_resolve()
453454
lock_amount = pi.is_amount_locked()
454455
lock_max = lock_amount or pi.type not in [PaymentIdentifierType.SPK, PaymentIdentifierType.BIP21]
455456

@@ -491,8 +492,9 @@ def update_fields(self):
491492
amount_valid = is_spk_script or bool(self.amount_e.get_amount())
492493

493494
self.send_button.setEnabled(not pi_unusable and amount_valid and not pi.has_expired())
494-
self.save_button.setEnabled(not pi_unusable and not is_spk_script and not pi.has_expired() and \
495-
pi.type not in [PaymentIdentifierType.LNURLP, PaymentIdentifierType.LNADDR])
495+
self.save_button.setEnabled(not pi_unusable and not is_spk_script and pi.type not in [ \
496+
PaymentIdentifierType.LNURLP, PaymentIdentifierType.LNADDR, PaymentIdentifierType.BOLT12_OFFER
497+
])
496498

497499
self.invoice_error.setText(_('Expired') if pi.has_expired() else '')
498500

@@ -580,6 +582,8 @@ def on_finalize_done(self, pi: PaymentIdentifier):
580582
self.show_error(pi.error)
581583
return
582584
invoice = pi.bolt11
585+
if not invoice and pi.bolt12_offer:
586+
invoice = Invoice.from_bolt12_invoice_tlv(pi.bolt12_invoice_tlv)
583587
self.pending_invoice = invoice
584588
self.logger.debug(f'after finalize invoice: {invoice!r}')
585589
self.do_pay_invoice(invoice)

0 commit comments

Comments
 (0)