qt: move wait_for_swap_transport to SwapManager
What changed, and why it matters
This commit simply moves an existing helper function from the Qt user-interface layer into the core swap-management module. The code's behavior is unchanged; it is a routine internal refactoring with no visible security implications.
No security action required; treat as a normal refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff relocates wait_for_swap_transport from electrum/gui/qt/confirm_tx_dialog.py to electrum/submarine_swaps.py and updates the single call site to use self.swap_manager.wait_for_swap_transport(transport). The method body is identical, including the timeout, logging, and return-value logic. No functional changes are introduced.
Changed components
electrum/gui/qt/confirm_tx_dialog.pyelectrum/submarine_swaps.pyInspect captured patch +31 / −31
diff --git a/electrum/gui/qt/confirm_tx_dialog.py b/electrum/gui/qt/confirm_tx_dialog.py
index f58e03d..9a27c51 100644
--- a/electrum/gui/qt/confirm_tx_dialog.py
+++ b/electrum/gui/qt/confirm_tx_dialog.py
@@ -798,7 +798,7 @@ class TxEditor(WindowModalDialog, QtEventListener, Logger):
else:
assert isinstance(transport, HttpTransport)
asyncio.create_task(transport.get_pairs_just_once())
- if not await self.wait_for_swap_transport(transport):
+ if not await self.swap_manager.wait_for_swap_transport(transport):
return
self.swap_transport = transport
except Exception:
@@ -813,36 +813,6 @@ class TxEditor(WindowModalDialog, QtEventListener, Logger):
get_asyncio_loop(),
)
- async def wait_for_swap_transport(self, new_swap_transport: Union[HttpTransport, NostrTransport]) -> bool:
- """
- Wait until we found the announcement event of the configured swap server.
- If it is not found but the relay connection is established return True anyway,
- the user will then need to select a different swap server.
- """
- timeout = new_swap_transport.connect_timeout + 1
- try:
- # swap_manager.is_initialized gets set once we got pairs of the configured swap server
- await wait_for2(self.swap_manager.is_initialized.wait(), timeout)
- except asyncio.TimeoutError:
- self.logger.debug(f"swap transport initialization timed out after {timeout} sec")
-
- if self.swap_manager.is_initialized.is_set():
- return True
-
- # timed out above
- if self.config.SWAPSERVER_URL:
- # http swapserver didn't return pairs
- self.logger.error(f"couldn't request pairs from {self.config.SWAPSERVER_URL=}")
- return False
- elif new_swap_transport.is_connected.is_set():
- assert isinstance(new_swap_transport, NostrTransport)
- # couldn't find announcement of configured swapserver, maybe it is gone.
- # update_submarine_payment_tab will tell the user to select a different swap server.
- return True
-
- # we couldn't even connect to the relays, this transport is useless. maybe network issues.
- return False
-
@qt_event_listener
def on_event_swap_provider_changed(self):
self.swap_availability_changed.emit()
diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py
index f297497..c611482 100644
--- a/electrum/submarine_swaps.py
+++ b/electrum/submarine_swaps.py
@@ -341,6 +341,36 @@ class SwapManager(Logger):
keypair = self.lnworker.nostr_keypair if self.is_server else generate_random_keypair()
return NostrTransport(self.config, self, keypair)
+ async def wait_for_swap_transport(self, new_swap_transport: 'SwapServerTransport') -> bool:
+ """
+ Wait until we found the announcement event of the configured swap server.
+ If it is not found but the relay connection is established return True anyway,
+ the user will then need to select a different swap server.
+ """
+ timeout = new_swap_transport.connect_timeout + 1
+ try:
+ # swap_manager.is_initialized gets set once we got pairs of the configured swap server
+ await wait_for2(self.is_initialized.wait(), timeout)
+ except asyncio.TimeoutError:
+ self.logger.debug(f"swap transport initialization timed out after {timeout} sec")
+
+ if self.is_initialized.is_set():
+ return True
+
+ # timed out above
+ if self.config.SWAPSERVER_URL:
+ # http swapserver didn't return pairs
+ self.logger.error(f"couldn't request pairs from {self.config.SWAPSERVER_URL=}")
+ return False
+ elif new_swap_transport.is_connected.is_set():
+ assert isinstance(new_swap_transport, NostrTransport)
+ # couldn't find announcement of configured swapserver, maybe it is gone.
+ # update_submarine_payment_tab will tell the user to select a different swap server.
+ return True
+
+ # we couldn't even connect to the relays, this transport is useless. maybe network issues.
+ return False
+
async def set_nostr_proof_of_work(self) -> None:
current_pow = get_nostr_ann_pow_amount(
self.lnworker.nostr_keypair.pubkey[1:],
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.