Browse Source

qt normal swap dialog: do not use run_from_another_thread, as it is blocking

master
ThomasV 1 year ago
parent
commit
5928dbbc47
  1. 27
      electrum/gui/qt/swap_dialog.py
  2. 2
      electrum/submarine_swaps.py

27
electrum/gui/qt/swap_dialog.py

@ -323,22 +323,21 @@ class SwapDialog(WindowModalDialog, QtEventListener):
dummy_tx = self._create_tx(onchain_amount)
assert dummy_tx
sm = self.swap_manager
coro = sm.request_normal_swap(
lightning_amount_sat=lightning_amount,
expected_onchain_amount_sat=onchain_amount,
channels=self.channels,
)
try:
swap, invoice = self.network.run_from_another_thread(coro)
except Exception as e:
self.window.show_error(str(e))
return
tx = sm.create_funding_tx(swap, dummy_tx, password=password)
coro2 = sm.wait_for_htlcs_and_broadcast(swap=swap, invoice=invoice, tx=tx)
self._current_swap = None
async def coro():
swap, invoice = await sm.request_normal_swap(
lightning_amount_sat=lightning_amount,
expected_onchain_amount_sat=onchain_amount,
channels=self.channels,
)
self._current_swap = swap
tx = sm.create_funding_tx(swap, dummy_tx, password=password)
txid = await sm.wait_for_htlcs_and_broadcast(swap=swap, invoice=invoice, tx=tx)
return txid
self.window.run_coroutine_dialog(
coro2, _('Awaiting swap payment...'),
coro(), _('Awaiting swap payment...'),
on_result=lambda funding_txid: self.window.on_swap_result(funding_txid, is_reverse=False),
on_cancelled=lambda: sm.cancel_normal_swap(swap))
on_cancelled=lambda: sm.cancel_normal_swap(self._current_swap))
def get_description(self):
onchain_funds = "onchain funds"

2
electrum/submarine_swaps.py

@ -253,6 +253,8 @@ class SwapManager(Logger):
def cancel_normal_swap(self, swap: SwapData):
""" we must not have broadcast the funding tx """
if swap is None:
return
if swap.funding_txid is not None:
self.logger.info(f'cannot cancel swap {swap.payment_hash.hex()}: already funded')
return

Loading…
Cancel
Save