Merge pull request #9620 from accumulator/lightning_pass_invoice_not_bolt11
refactor lnworker.pay_invoice to accept Invoice object instead of bolt11 string
This commit is contained in:
@@ -7,14 +7,15 @@ from PyQt6.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, pyqtEnum,
|
||||
|
||||
from electrum.i18n import _
|
||||
from electrum.logging import get_logger
|
||||
from electrum.invoices import (Invoice, PR_UNPAID, PR_EXPIRED, PR_UNKNOWN, PR_PAID, PR_INFLIGHT,
|
||||
PR_FAILED, PR_ROUTING, PR_UNCONFIRMED, PR_BROADCASTING, PR_BROADCAST, LN_EXPIRY_NEVER)
|
||||
from electrum.invoices import (
|
||||
Invoice, PR_UNPAID, PR_EXPIRED, PR_UNKNOWN, PR_PAID, PR_INFLIGHT, PR_FAILED, PR_ROUTING, PR_UNCONFIRMED,
|
||||
PR_BROADCASTING, PR_BROADCAST, LN_EXPIRY_NEVER
|
||||
)
|
||||
from electrum.transaction import PartialTxOutput, TxOutput
|
||||
from electrum.util import NotEnoughFunds, NoDynamicFeeEstimates
|
||||
from electrum.lnutil import format_short_channel_id
|
||||
from electrum.bitcoin import COIN, address_to_script
|
||||
from electrum.paymentrequest import PaymentRequest
|
||||
from electrum.payment_identifier import (PaymentIdentifier, PaymentIdentifierState, PaymentIdentifierType)
|
||||
from electrum.payment_identifier import PaymentIdentifier, PaymentIdentifierState, PaymentIdentifierType
|
||||
|
||||
from .qetypes import QEAmount
|
||||
from .qewallet import QEWallet
|
||||
@@ -57,7 +58,7 @@ class QEInvoice(QObject, QtEventListener):
|
||||
self._canPay = False
|
||||
self._key = None
|
||||
self._invoiceType = QEInvoice.Type.Invalid
|
||||
self._effectiveInvoice = None
|
||||
self._effectiveInvoice = None # type: Optional[Invoice]
|
||||
self._userinfo = ''
|
||||
self._lnprops = {}
|
||||
self._amount = QEAmount()
|
||||
|
||||
@@ -32,7 +32,7 @@ from ...fee_policy import FeePolicy
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from electrum.wallet import Abstract_Wallet
|
||||
from .qeinvoice import QEInvoice
|
||||
from electrum.invoices import Invoice
|
||||
|
||||
|
||||
class QEWallet(AuthMixin, QObject, QtEventListener):
|
||||
@@ -653,12 +653,12 @@ class QEWallet(AuthMixin, QObject, QtEventListener):
|
||||
self.paymentAuthRejected.emit()
|
||||
|
||||
@auth_protect(message=_('Pay lightning invoice?'), reject='ln_auth_rejected')
|
||||
def pay_lightning_invoice(self, invoice: 'QEInvoice'):
|
||||
def pay_lightning_invoice(self, invoice: 'Invoice'):
|
||||
amount_msat = invoice.get_amount_msat()
|
||||
|
||||
def pay_thread():
|
||||
try:
|
||||
coro = self.wallet.lnworker.pay_invoice(invoice.lightning_invoice, amount_msat=amount_msat)
|
||||
coro = self.wallet.lnworker.pay_invoice(invoice, amount_msat=amount_msat)
|
||||
fut = asyncio.run_coroutine_threadsafe(coro, get_asyncio_loop())
|
||||
fut.result()
|
||||
except Exception as e:
|
||||
|
||||
@@ -719,7 +719,7 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
if not self.question(msg):
|
||||
return
|
||||
self.save_pending_invoice()
|
||||
coro = lnworker.pay_invoice(invoice.lightning_invoice, amount_msat=amount_msat)
|
||||
coro = lnworker.pay_invoice(invoice, amount_msat=amount_msat)
|
||||
self.window.run_coroutine_from_thread(coro, _('Sending payment'))
|
||||
|
||||
def broadcast_transaction(self, tx: Transaction, *, payment_identifier: PaymentIdentifier = None):
|
||||
|
||||
@@ -671,7 +671,7 @@ class ElectrumGui(BaseElectrumGui, EventListener):
|
||||
if not self.question(msg):
|
||||
return
|
||||
self.save_pending_invoice(invoice)
|
||||
coro = self.wallet.lnworker.pay_invoice(invoice.lightning_invoice, amount_msat=amount_msat)
|
||||
coro = self.wallet.lnworker.pay_invoice(invoice, amount_msat=amount_msat)
|
||||
|
||||
#self.window.run_coroutine_from_thread(coro, _('Sending payment'))
|
||||
self.show_message(_("Please wait..."), getchar=False)
|
||||
|
||||
Reference in New Issue
Block a user