qt normal swap dialog: do not use run_from_another_thread, as it is blocking
This commit is contained in:
@@ -323,22 +323,21 @@ class SwapDialog(WindowModalDialog, QtEventListener):
|
|||||||
dummy_tx = self._create_tx(onchain_amount)
|
dummy_tx = self._create_tx(onchain_amount)
|
||||||
assert dummy_tx
|
assert dummy_tx
|
||||||
sm = self.swap_manager
|
sm = self.swap_manager
|
||||||
coro = sm.request_normal_swap(
|
self._current_swap = None
|
||||||
lightning_amount_sat=lightning_amount,
|
async def coro():
|
||||||
expected_onchain_amount_sat=onchain_amount,
|
swap, invoice = await sm.request_normal_swap(
|
||||||
channels=self.channels,
|
lightning_amount_sat=lightning_amount,
|
||||||
)
|
expected_onchain_amount_sat=onchain_amount,
|
||||||
try:
|
channels=self.channels,
|
||||||
swap, invoice = self.network.run_from_another_thread(coro)
|
)
|
||||||
except Exception as e:
|
self._current_swap = swap
|
||||||
self.window.show_error(str(e))
|
tx = sm.create_funding_tx(swap, dummy_tx, password=password)
|
||||||
return
|
txid = await sm.wait_for_htlcs_and_broadcast(swap=swap, invoice=invoice, tx=tx)
|
||||||
tx = sm.create_funding_tx(swap, dummy_tx, password=password)
|
return txid
|
||||||
coro2 = sm.wait_for_htlcs_and_broadcast(swap=swap, invoice=invoice, tx=tx)
|
|
||||||
self.window.run_coroutine_dialog(
|
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_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):
|
def get_description(self):
|
||||||
onchain_funds = "onchain funds"
|
onchain_funds = "onchain funds"
|
||||||
|
|||||||
@@ -253,6 +253,8 @@ class SwapManager(Logger):
|
|||||||
|
|
||||||
def cancel_normal_swap(self, swap: SwapData):
|
def cancel_normal_swap(self, swap: SwapData):
|
||||||
""" we must not have broadcast the funding tx """
|
""" we must not have broadcast the funding tx """
|
||||||
|
if swap is None:
|
||||||
|
return
|
||||||
if swap.funding_txid is not None:
|
if swap.funding_txid is not None:
|
||||||
self.logger.info(f'cannot cancel swap {swap.payment_hash.hex()}: already funded')
|
self.logger.info(f'cannot cancel swap {swap.payment_hash.hex()}: already funded')
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user