register distinction between address and script for SPK type payment identifiers and allow zero amount for
script destinations. This is mainly to support OP_RETURN outputs, which typically have a zero amount output value, but as we don't special case OP_RETURN, this is currently done for all non-address scripts Also, it's probably good to add a warning popup for OP_RETURN outputs with a non-zero output value, but this would also need special casing for OP_RETURN. Saving of script output payment identifiers is disabled for now, as reading the script from the stored invoice back into human-readable form is currently not implemented, and currently only lightning invoices or address output is supported.
This commit is contained in:
@@ -205,9 +205,14 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
|
||||
def on_amount_changed(self, text):
|
||||
# FIXME: implement full valid amount check to enable/disable Pay button
|
||||
pi_valid = self.payto_e.payment_identifier.is_valid() if self.payto_e.payment_identifier else False
|
||||
pi_error = self.payto_e.payment_identifier.is_error() if pi_valid else False
|
||||
self.send_button.setEnabled(bool(self.amount_e.get_amount()) and pi_valid and not pi_error)
|
||||
pi = self.payto_e.payment_identifier
|
||||
if not pi:
|
||||
self.send_button.setEnabled(False)
|
||||
return
|
||||
pi_error = pi.is_error() if pi.is_valid() else False
|
||||
is_spk_script = pi.type == PaymentIdentifierType.SPK and not pi.spk_is_address
|
||||
valid_amount = is_spk_script or bool(self.amount_e.get_amount())
|
||||
self.send_button.setEnabled(pi.is_valid() and not pi_error and valid_amount)
|
||||
|
||||
def do_paste(self):
|
||||
self.logger.debug('do_paste')
|
||||
@@ -224,16 +229,20 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
self.show_error(_('Invalid payment identifier'))
|
||||
|
||||
def spend_max(self):
|
||||
if self.payto_e.payment_identifier is None:
|
||||
pi = self.payto_e.payment_identifier
|
||||
|
||||
if pi is None or pi.type == PaymentIdentifierType.UNKNOWN:
|
||||
return
|
||||
|
||||
assert self.payto_e.payment_identifier.type in [PaymentIdentifierType.SPK, PaymentIdentifierType.MULTILINE,
|
||||
PaymentIdentifierType.BIP21, PaymentIdentifierType.OPENALIAS]
|
||||
assert not self.payto_e.payment_identifier.is_amount_locked()
|
||||
assert pi.type in [PaymentIdentifierType.SPK, PaymentIdentifierType.MULTILINE,
|
||||
PaymentIdentifierType.BIP21, PaymentIdentifierType.OPENALIAS]
|
||||
|
||||
if pi.type == PaymentIdentifierType.BIP21:
|
||||
assert 'amount' not in pi.bip21
|
||||
|
||||
if run_hook('abort_send', self):
|
||||
return
|
||||
outputs = self.payto_e.payment_identifier.get_onchain_outputs('!')
|
||||
outputs = pi.get_onchain_outputs('!')
|
||||
if not outputs:
|
||||
return
|
||||
make_tx = lambda fee_est, *, confirmed_only=False: self.wallet.make_unsigned_transaction(
|
||||
@@ -446,10 +455,13 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
self.spend_max()
|
||||
|
||||
pi_unusable = pi.is_error() or (not self.wallet.has_lightning() and not pi.is_onchain())
|
||||
is_spk_script = pi.type == PaymentIdentifierType.SPK and not pi.spk_is_address
|
||||
|
||||
self.send_button.setEnabled(not pi_unusable and bool(self.amount_e.get_amount()) and not pi.has_expired())
|
||||
self.save_button.setEnabled(not pi_unusable and pi.type not in [PaymentIdentifierType.LNURLP,
|
||||
PaymentIdentifierType.LNADDR])
|
||||
amount_valid = is_spk_script or bool(self.amount_e.get_amount())
|
||||
|
||||
self.send_button.setEnabled(not pi_unusable and amount_valid and not pi.has_expired())
|
||||
self.save_button.setEnabled(not pi_unusable and not is_spk_script and \
|
||||
pi.type not in [PaymentIdentifierType.LNURLP, PaymentIdentifierType.LNADDR])
|
||||
|
||||
def _handle_payment_identifier(self):
|
||||
self.update_fields()
|
||||
@@ -479,11 +491,8 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
def read_invoice(self) -> Optional[Invoice]:
|
||||
if self.check_payto_line_and_show_errors():
|
||||
return
|
||||
amount_sat = self.read_amount()
|
||||
if not amount_sat:
|
||||
self.show_error(_('No amount'))
|
||||
return
|
||||
|
||||
amount_sat = self.read_amount()
|
||||
invoice = invoice_from_payment_identifier(
|
||||
self.payto_e.payment_identifier, self.wallet, amount_sat, self.get_message())
|
||||
if not invoice:
|
||||
@@ -551,15 +560,19 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
def do_edit_invoice(self, invoice: 'Invoice'): # FIXME broken
|
||||
assert not bool(invoice.get_amount_sat())
|
||||
text = invoice.lightning_invoice if invoice.is_lightning() else invoice.get_address()
|
||||
self.payto_e._on_input_btn(text)
|
||||
self.set_payment_identifier(text)
|
||||
self.amount_e.setFocus()
|
||||
# disable save button, because it would create a new invoice
|
||||
self.save_button.setEnabled(False)
|
||||
|
||||
def do_pay_invoice(self, invoice: 'Invoice'):
|
||||
if not bool(invoice.get_amount_sat()):
|
||||
self.show_error(_('No amount'))
|
||||
return
|
||||
pi = self.payto_e.payment_identifier
|
||||
if pi.type == PaymentIdentifierType.SPK and not pi.spk_is_address:
|
||||
pass
|
||||
else:
|
||||
self.show_error(_('No amount'))
|
||||
return
|
||||
if invoice.is_lightning():
|
||||
self.pay_lightning_invoice(invoice)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user