qt send tab: (regression) fix handling multiline fmt for single line
fixes #6761
This commit is contained in:
@@ -73,7 +73,7 @@ class PayToEdit(CompletionTextEdit, ScanQRTextEdit, Logger):
|
|||||||
self.c = None
|
self.c = None
|
||||||
self.textChanged.connect(self.check_text)
|
self.textChanged.connect(self.check_text)
|
||||||
self.outputs = [] # type: List[PartialTxOutput]
|
self.outputs = [] # type: List[PartialTxOutput]
|
||||||
self.errors = [] # type: Sequence[PayToLineError]
|
self.errors = [] # type: List[PayToLineError]
|
||||||
self.is_pr = False
|
self.is_pr = False
|
||||||
self.is_alias = False
|
self.is_alias = False
|
||||||
self.update_size()
|
self.update_size()
|
||||||
@@ -145,15 +145,18 @@ class PayToEdit(CompletionTextEdit, ScanQRTextEdit, Logger):
|
|||||||
return
|
return
|
||||||
# filter out empty lines
|
# filter out empty lines
|
||||||
lines = [i for i in self.lines() if i]
|
lines = [i for i in self.lines() if i]
|
||||||
outputs = [] # type: List[PartialTxOutput]
|
|
||||||
total = 0
|
|
||||||
self.payto_scriptpubkey = None
|
self.payto_scriptpubkey = None
|
||||||
self.lightning_invoice = None
|
self.lightning_invoice = None
|
||||||
|
self.outputs = []
|
||||||
|
|
||||||
if len(lines) == 1:
|
if len(lines) == 1:
|
||||||
data = lines[0]
|
data = lines[0]
|
||||||
|
# try bip21 URI
|
||||||
if data.startswith("bitcoin:"):
|
if data.startswith("bitcoin:"):
|
||||||
self.win.pay_to_URI(data)
|
self.win.pay_to_URI(data)
|
||||||
return
|
return
|
||||||
|
# try LN invoice
|
||||||
bolt11_invoice = maybe_extract_bolt11_invoice(data)
|
bolt11_invoice = maybe_extract_bolt11_invoice(data)
|
||||||
if bolt11_invoice is not None:
|
if bolt11_invoice is not None:
|
||||||
try:
|
try:
|
||||||
@@ -163,24 +166,40 @@ class PayToEdit(CompletionTextEdit, ScanQRTextEdit, Logger):
|
|||||||
else:
|
else:
|
||||||
self.lightning_invoice = bolt11_invoice
|
self.lightning_invoice = bolt11_invoice
|
||||||
return
|
return
|
||||||
|
# try "address, amount" on-chain format
|
||||||
|
try:
|
||||||
|
self._parse_as_multiline(lines, raise_errors=True)
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
# try address/script
|
||||||
try:
|
try:
|
||||||
self.payto_scriptpubkey = self.parse_output(data)
|
self.payto_scriptpubkey = self.parse_output(data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.errors.append(PayToLineError(line_content=data, exc=e))
|
self.errors.append(PayToLineError(line_content=data, exc=e))
|
||||||
if self.payto_scriptpubkey:
|
else:
|
||||||
self.win.set_onchain(True)
|
self.win.set_onchain(True)
|
||||||
self.win.lock_amount(False)
|
self.win.lock_amount(False)
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
# there are multiple lines
|
||||||
|
self._parse_as_multiline(lines, raise_errors=False)
|
||||||
|
|
||||||
# there are multiple lines
|
def _parse_as_multiline(self, lines, *, raise_errors: bool):
|
||||||
|
outputs = [] # type: List[PartialTxOutput]
|
||||||
|
total = 0
|
||||||
is_max = False
|
is_max = False
|
||||||
for i, line in enumerate(lines):
|
for i, line in enumerate(lines):
|
||||||
try:
|
try:
|
||||||
output = self.parse_address_and_amount(line)
|
output = self.parse_address_and_amount(line)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.errors.append(PayToLineError(
|
if raise_errors:
|
||||||
idx=i, line_content=line.strip(), exc=e, is_multiline=True))
|
raise
|
||||||
continue
|
else:
|
||||||
|
self.errors.append(PayToLineError(
|
||||||
|
idx=i, line_content=line.strip(), exc=e, is_multiline=True))
|
||||||
|
continue
|
||||||
outputs.append(output)
|
outputs.append(output)
|
||||||
if output.value == '!':
|
if output.value == '!':
|
||||||
is_max = True
|
is_max = True
|
||||||
|
|||||||
Reference in New Issue
Block a user