qt: better handle unparseable URIs
fixes https://github.com/spesmilo/electrum/issues/7941
This commit is contained in:
@@ -382,12 +382,11 @@ class ElectrumGui(BaseElectrumGui, Logger):
|
|||||||
path = os.path.join(wallet_dir, filename)
|
path = os.path.join(wallet_dir, filename)
|
||||||
self.start_new_window(path, uri=None, force_wizard=True)
|
self.start_new_window(path, uri=None, force_wizard=True)
|
||||||
return
|
return
|
||||||
if uri:
|
|
||||||
window.handle_payment_identifier(uri)
|
|
||||||
window.bring_to_top()
|
window.bring_to_top()
|
||||||
window.setWindowState(window.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
|
window.setWindowState(window.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
|
||||||
|
|
||||||
window.activateWindow()
|
window.activateWindow()
|
||||||
|
if uri:
|
||||||
|
window.handle_payment_identifier(uri)
|
||||||
return window
|
return window
|
||||||
|
|
||||||
def _start_wizard_to_select_or_create_wallet(self, path) -> Optional[Abstract_Wallet]:
|
def _start_wizard_to_select_or_create_wallet(self, path) -> Optional[Abstract_Wallet]:
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ from electrum.i18n import _
|
|||||||
from electrum.util import (format_time, get_asyncio_loop,
|
from electrum.util import (format_time, get_asyncio_loop,
|
||||||
UserCancelled, profiler,
|
UserCancelled, profiler,
|
||||||
bh2u, bfh, InvalidPassword,
|
bh2u, bfh, InvalidPassword,
|
||||||
UserFacingException,
|
UserFacingException, FailedToParsePaymentIdentifier,
|
||||||
get_new_wallet_name, send_exception_to_crash_reporter,
|
get_new_wallet_name, send_exception_to_crash_reporter,
|
||||||
AddTransactionException, BITCOIN_BIP21_URI_SCHEME, os_chmod)
|
AddTransactionException, BITCOIN_BIP21_URI_SCHEME, os_chmod)
|
||||||
from electrum.invoices import PR_PAID, Invoice
|
from electrum.invoices import PR_PAID, Invoice
|
||||||
@@ -1316,7 +1316,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
|||||||
return clayout.selected_index()
|
return clayout.selected_index()
|
||||||
|
|
||||||
def handle_payment_identifier(self, *args, **kwargs):
|
def handle_payment_identifier(self, *args, **kwargs):
|
||||||
self.send_tab.handle_payment_identifier(*args, **kwargs)
|
try:
|
||||||
|
self.send_tab.handle_payment_identifier(*args, **kwargs)
|
||||||
|
except FailedToParsePaymentIdentifier as e:
|
||||||
|
self.show_error(str(e))
|
||||||
|
|
||||||
def set_frozen_state_of_addresses(self, addrs, freeze: bool):
|
def set_frozen_state_of_addresses(self, addrs, freeze: bool):
|
||||||
self.wallet.set_frozen_state_of_addresses(addrs, freeze)
|
self.wallet.set_frozen_state_of_addresses(addrs, freeze)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ from PyQt5.QtGui import QFontMetrics, QFont
|
|||||||
from PyQt5.QtWidgets import QApplication
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
|
||||||
from electrum import bitcoin
|
from electrum import bitcoin
|
||||||
from electrum.util import bfh, parse_max_spend
|
from electrum.util import bfh, parse_max_spend, FailedToParsePaymentIdentifier
|
||||||
from electrum.transaction import PartialTxOutput
|
from electrum.transaction import PartialTxOutput
|
||||||
from electrum.bitcoin import opcodes, construct_script
|
from electrum.bitcoin import opcodes, construct_script
|
||||||
from electrum.logging import Logger
|
from electrum.logging import Logger
|
||||||
@@ -212,7 +212,7 @@ class PayToEdit(CompletionTextEdit, ScanQRTextEdit, Logger):
|
|||||||
except LNURLError as e:
|
except LNURLError as e:
|
||||||
self.logger.exception("")
|
self.logger.exception("")
|
||||||
self.send_tab.show_error(e)
|
self.send_tab.show_error(e)
|
||||||
except ValueError:
|
except FailedToParsePaymentIdentifier:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from electrum import util, paymentrequest
|
|||||||
from electrum import lnutil
|
from electrum import lnutil
|
||||||
from electrum.plugin import run_hook
|
from electrum.plugin import run_hook
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.util import (get_asyncio_loop, bh2u,
|
from electrum.util import (get_asyncio_loop, bh2u, FailedToParsePaymentIdentifier,
|
||||||
InvalidBitcoinURI, maybe_extract_lightning_payment_identifier, NotEnoughFunds,
|
InvalidBitcoinURI, maybe_extract_lightning_payment_identifier, NotEnoughFunds,
|
||||||
NoDynamicFeeEstimates, InvoiceError, parse_max_spend)
|
NoDynamicFeeEstimates, InvoiceError, parse_max_spend)
|
||||||
from electrum.invoices import PR_PAID, Invoice
|
from electrum.invoices import PR_PAID, Invoice
|
||||||
@@ -477,7 +477,8 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
|||||||
elif text.lower().startswith(util.BITCOIN_BIP21_URI_SCHEME + ':'):
|
elif text.lower().startswith(util.BITCOIN_BIP21_URI_SCHEME + ':'):
|
||||||
self.set_bip21(text, can_use_network=can_use_network)
|
self.set_bip21(text, can_use_network=can_use_network)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Could not handle payment identifier.")
|
truncated_text = f"{text[:100]}..." if len(text) > 100 else text
|
||||||
|
raise FailedToParsePaymentIdentifier(f"Could not handle payment identifier:\n{truncated_text}")
|
||||||
# update fiat amount
|
# update fiat amount
|
||||||
self.amount_e.textEdited.emit("")
|
self.amount_e.textEdited.emit("")
|
||||||
self.window.show_send_tab()
|
self.window.show_send_tab()
|
||||||
|
|||||||
@@ -1111,6 +1111,10 @@ def is_uri(data: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class FailedToParsePaymentIdentifier(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Python bug (http://bugs.python.org/issue1927) causes raw_input
|
# Python bug (http://bugs.python.org/issue1927) causes raw_input
|
||||||
# to be redirected improperly between stdin/stderr on Unix systems
|
# to be redirected improperly between stdin/stderr on Unix systems
|
||||||
#TODO: py3
|
#TODO: py3
|
||||||
|
|||||||
Reference in New Issue
Block a user