@ -4,7 +4,7 @@ from PyQt6.QtCore import pyqtSignal
from PyQt6 . QtWidgets import QLabel , QVBoxLayout , QGridLayout , QPushButton
from electrum . i18n import _
from electrum . util import NotEnoughFunds , NoDynamicFeeEstimates
from electrum . util import NotEnoughFunds , NoDynamicFeeEstimates , UserCancelled
from electrum . bitcoin import DummyAddress
from electrum . transaction import PartialTxOutput , PartialTransaction
@ -319,25 +319,33 @@ class SwapDialog(WindowModalDialog, QtEventListener):
recv_amount = self . recv_amount_e . get_amount ( )
self . ok_button . setEnabled ( bool ( send_amount ) and bool ( recv_amount ) )
def do_normal_swap ( self , lightning_amount , onchain_amount , password ) :
async def _ do_normal_swap( self , lightning_amount , onchain_amount , password ) :
dummy_tx = self . _create_tx ( onchain_amount )
assert dummy_tx
sm = self . swap_manager
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
def do_normal_swap ( self , lightning_amount , onchain_amount , password ) :
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 (
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 ( self . _current_swap ) )
coro = self . _do_normal_swap ( lightning_amount , onchain_amount , password )
try :
funding_txid = self . window . run_coroutine_dialog ( coro , _ ( ' Awaiting swap payment... ' ) )
except UserCancelled :
self . swap_manager . cancel_normal_swap ( self . _current_swap )
self . window . show_message ( _ ( ' Swap cancelled ' ) )
return
except Exception as e :
self . window . show_error ( str ( e ) )
return
self . window . on_swap_result ( funding_txid , is_reverse = False )
def get_description ( self ) :
onchain_funds = " onchain funds "