qml: actually do the x509 validation for bip70
as in other GUIs
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import threading
|
import threading
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
import asyncio
|
import asyncio
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ class QEInvoice(QObject):
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
self._wallet = None
|
self._wallet = None # type: Optional[QEWallet]
|
||||||
self._canSave = False
|
self._canSave = False
|
||||||
self._canPay = False
|
self._canPay = False
|
||||||
self._key = None
|
self._key = None
|
||||||
@@ -134,7 +134,7 @@ class QEInvoiceParser(QEInvoice):
|
|||||||
lnurlRetrieved = pyqtSignal()
|
lnurlRetrieved = pyqtSignal()
|
||||||
lnurlError = pyqtSignal([str,str], arguments=['code', 'message'])
|
lnurlError = pyqtSignal([str,str], arguments=['code', 'message'])
|
||||||
|
|
||||||
_bip70PrResolvedSignal = pyqtSignal([PaymentRequest], arguments=['request'])
|
_bip70PrResolvedSignal = pyqtSignal([PaymentRequest], arguments=['pr'])
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
@@ -371,12 +371,19 @@ class QEInvoiceParser(QEInvoice):
|
|||||||
URI=uri
|
URI=uri
|
||||||
)
|
)
|
||||||
|
|
||||||
def _bip70_payment_request_resolved(self, request: 'PaymentRequest'):
|
def _bip70_payment_request_resolved(self, pr: 'PaymentRequest'):
|
||||||
self._logger.debug('resolved payment request')
|
self._logger.debug('resolved payment request')
|
||||||
outputs = request.get_outputs()
|
if pr.verify(self._wallet.wallet.contacts):
|
||||||
invoice = self.create_onchain_invoice(outputs, None, request, None)
|
invoice = Invoice.from_bip70_payreq(pr, height=0)
|
||||||
self.setValidOnchainInvoice(invoice)
|
if self._wallet.wallet.get_invoice_status(invoice) == PR_PAID:
|
||||||
self.validationSuccess.emit()
|
self.validationError.emit('unknown', _('Invoice already paid'))
|
||||||
|
elif pr.has_expired():
|
||||||
|
self.validationError.emit('unknown', _('Payment request has expired'))
|
||||||
|
else:
|
||||||
|
self.setValidOnchainInvoice(invoice)
|
||||||
|
self.validationSuccess.emit()
|
||||||
|
else:
|
||||||
|
self.validationError.emit('unknown', f"invoice error:\n{pr.error}")
|
||||||
|
|
||||||
def validateRecipient(self, recipient):
|
def validateRecipient(self, recipient):
|
||||||
if not recipient:
|
if not recipient:
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ class PaymentRequest:
|
|||||||
self.payment_url = self.details.payment_url
|
self.payment_url = self.details.payment_url
|
||||||
|
|
||||||
def verify(self, contacts):
|
def verify(self, contacts):
|
||||||
|
# FIXME: we should enforce that this method was called before we attempt payment
|
||||||
if self.error:
|
if self.error:
|
||||||
return False
|
return False
|
||||||
if not self.raw:
|
if not self.raw:
|
||||||
|
|||||||
Reference in New Issue
Block a user