payment identifier types as enum
This commit is contained in:
@@ -17,7 +17,7 @@ from electrum.lnurl import decode_lnurl, request_lnurl, callback_lnurl
|
||||
from electrum.bitcoin import COIN
|
||||
from electrum.paymentrequest import PaymentRequest
|
||||
from electrum.payment_identifier import (parse_bip21_URI, InvalidBitcoinURI, maybe_extract_lightning_payment_identifier,
|
||||
PaymentIdentifier, PaymentIdentifierState)
|
||||
PaymentIdentifier, PaymentIdentifierState, PaymentIdentifierType)
|
||||
|
||||
from .qetypes import QEAmount
|
||||
from .qewallet import QEWallet
|
||||
@@ -491,7 +491,8 @@ class QEInvoiceParser(QEInvoice):
|
||||
return
|
||||
|
||||
self._pi = PaymentIdentifier(self._wallet.wallet, recipient)
|
||||
if not self._pi.is_valid() or self._pi.type not in ['spk', 'bip21', 'bip70', 'bolt11', 'lnurl']:
|
||||
if not self._pi.is_valid() or self._pi.type not in [PaymentIdentifierType.SPK, PaymentIdentifierType.BIP21,
|
||||
PaymentIdentifierType.BIP70, PaymentIdentifierType.BOLT11, PaymentIdentifierType.LNURLP]:
|
||||
self.validationError.emit('unknown', _('Unknown invoice'))
|
||||
return
|
||||
|
||||
@@ -502,23 +503,23 @@ class QEInvoiceParser(QEInvoice):
|
||||
self.resolve_pi()
|
||||
return
|
||||
|
||||
if self._pi.type == 'lnurl':
|
||||
if self._pi.type == PaymentIdentifierType.LNURLP:
|
||||
self.on_lnurl(self._pi.lnurl_data)
|
||||
return
|
||||
|
||||
if self._pi.type == 'bip70':
|
||||
if self._pi.type == PaymentIdentifierType.BIP70:
|
||||
self._bip70_payment_request_resolved(self._pi.bip70_data)
|
||||
return
|
||||
|
||||
if self._pi.is_available():
|
||||
if self._pi.type == 'spk':
|
||||
if self._pi.type == PaymentIdentifierType.SPK:
|
||||
outputs = [PartialTxOutput(scriptpubkey=self._pi.spk, value=0)]
|
||||
invoice = self.create_onchain_invoice(outputs, None, None, None)
|
||||
self._logger.debug(repr(invoice))
|
||||
self.setValidOnchainInvoice(invoice)
|
||||
self.validationSuccess.emit()
|
||||
return
|
||||
elif self._pi.type == 'bolt11':
|
||||
elif self._pi.type == PaymentIdentifierType.BOLT11:
|
||||
lninvoice = Invoice.from_bech32(self._pi.bolt11)
|
||||
if not self._wallet.wallet.has_lightning() and not lninvoice.get_address():
|
||||
self.validationError.emit('no_lightning',
|
||||
@@ -530,7 +531,7 @@ class QEInvoiceParser(QEInvoice):
|
||||
|
||||
self.setValidLightningInvoice(lninvoice)
|
||||
self.validationSuccess.emit()
|
||||
elif self._pi.type == 'bip21':
|
||||
elif self._pi.type == PaymentIdentifierType.BIP21:
|
||||
if self._wallet.wallet.has_lightning() and self._wallet.wallet.lnworker.channels and self._pi.bolt11:
|
||||
lninvoice = Invoice.from_bech32(self._pi.bolt11)
|
||||
self.setValidLightningInvoice(lninvoice)
|
||||
|
||||
@@ -16,7 +16,7 @@ from electrum.util import NotEnoughFunds, NoDynamicFeeEstimates, parse_max_spend
|
||||
from electrum.invoices import PR_PAID, Invoice, PR_BROADCASTING, PR_BROADCAST
|
||||
from electrum.transaction import Transaction, PartialTxInput, PartialTxOutput
|
||||
from electrum.network import TxBroadcastError, BestEffortRequestFailed
|
||||
from electrum.payment_identifier import PaymentIdentifierState
|
||||
from electrum.payment_identifier import PaymentIdentifierState, PaymentIdentifierType
|
||||
|
||||
from .amountedit import AmountEdit, BTCAmountEdit, SizedFreezableLineEdit
|
||||
from .paytoedit import InvalidPaymentIdentifier
|
||||
@@ -206,7 +206,7 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
|
||||
def spend_max(self):
|
||||
assert self.payto_e.payment_identifier is not None
|
||||
assert self.payto_e.payment_identifier.type in ['spk', 'multiline']
|
||||
assert self.payto_e.payment_identifier.type in [PaymentIdentifierType.SPK, PaymentIdentifierType.MULTILINE]
|
||||
if run_hook('abort_send', self):
|
||||
return
|
||||
outputs = self.payto_e.payment_identifier.get_onchain_outputs('!')
|
||||
@@ -383,10 +383,10 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
self.send_button.setEnabled(False)
|
||||
return
|
||||
|
||||
lock_recipient = pi.type != 'spk' \
|
||||
and not (pi.type == 'emaillike' and pi.is_state(PaymentIdentifierState.NOT_FOUND))
|
||||
lock_recipient = pi.type != PaymentIdentifierType.SPK \
|
||||
and not (pi.type == PaymentIdentifierType.EMAILLIKE and pi.is_state(PaymentIdentifierState.NOT_FOUND))
|
||||
lock_max = pi.is_amount_locked() \
|
||||
or pi.type in ['bolt11', 'lnurl', 'lightningaddress']
|
||||
or pi.type in [PaymentIdentifierType.BOLT11, PaymentIdentifierType.LNURLP, PaymentIdentifierType.LNADDR]
|
||||
self.lock_fields(lock_recipient=lock_recipient,
|
||||
lock_amount=pi.is_amount_locked(),
|
||||
lock_max=lock_max,
|
||||
|
||||
Reference in New Issue
Block a user