submarine swaps: use a short expiry with hold invoices, and display result to the user
This commit is contained in:
@@ -325,7 +325,15 @@ class SwapDialog(WindowModalDialog, QtEventListener):
|
||||
tx=tx,
|
||||
channels=self.channels,
|
||||
)
|
||||
self.window.run_coroutine_from_thread(coro, _('Swapping funds'))
|
||||
def on_result(txid):
|
||||
msg = _("Submarine swap") + ': ' + (_("Success") if txid else _("Expired")) + '\n'
|
||||
if txid:
|
||||
msg += _("Funding transaction") + ': ' + txid + '\n'
|
||||
msg += _("Please remain online until your transaction is confirmed")
|
||||
else:
|
||||
msg += _("The server failed to send lightning funds to you")
|
||||
self.window.show_error_signal.emit(msg)
|
||||
self.window.run_coroutine_from_thread(coro, _('Swapping funds'), on_result=on_result)
|
||||
|
||||
def get_description(self):
|
||||
onchain_funds = "onchain funds"
|
||||
|
||||
@@ -20,6 +20,7 @@ from .lnutil import REDEEM_AFTER_DOUBLE_SPENT_DELAY, ln_dummy_address
|
||||
from .bitcoin import dust_threshold
|
||||
from .logging import Logger
|
||||
from .lnutil import hex_to_bytes
|
||||
from .lnaddr import lndecode
|
||||
from .json_db import StoredObject, stored_in
|
||||
from . import constants
|
||||
from .address_synchronizer import TX_HEIGHT_LOCAL
|
||||
@@ -392,7 +393,18 @@ class SwapManager(Logger):
|
||||
self.lnworker.register_callback_for_hold_invoice(payment_hash, self.hold_invoice_callback)
|
||||
return swap, invoice, prepay_invoice
|
||||
|
||||
def add_normal_swap(self, *, redeem_script=None, locktime=None, onchain_amount_sat=None, lightning_amount_sat=None, payment_hash=None, our_privkey=None, their_pubkey=None, invoice=None, prepay=None):
|
||||
def add_normal_swap(
|
||||
self, *,
|
||||
redeem_script=None,
|
||||
locktime=None,
|
||||
onchain_amount_sat=None,
|
||||
lightning_amount_sat=None,
|
||||
payment_hash=None,
|
||||
our_privkey=None,
|
||||
their_pubkey=None,
|
||||
invoice=None,
|
||||
prepay=None,
|
||||
):
|
||||
""" if invoice is None, create a hold invoice """
|
||||
if prepay:
|
||||
prepay_amount_sat = self.get_claim_fee() * 2
|
||||
@@ -405,7 +417,7 @@ class SwapManager(Logger):
|
||||
payment_hash=payment_hash,
|
||||
amount_msat=invoice_amount_sat * 1000,
|
||||
message='Submarine swap',
|
||||
expiry=3600 * 24,
|
||||
expiry=300,
|
||||
fallback_address=None,
|
||||
channels=None,
|
||||
)
|
||||
@@ -418,7 +430,7 @@ class SwapManager(Logger):
|
||||
payment_hash=prepay_hash,
|
||||
amount_msat=prepay_amount_sat * 1000,
|
||||
message='Submarine swap mining fees',
|
||||
expiry=3600 * 24,
|
||||
expiry=300,
|
||||
fallback_address=None,
|
||||
channels=None,
|
||||
)
|
||||
@@ -641,7 +653,8 @@ class SwapManager(Logger):
|
||||
await self.broadcast_funding_tx(swap, tx)
|
||||
self.lnworker.register_callback_for_hold_invoice(payment_hash, callback)
|
||||
# wait for funding tx
|
||||
while swap.funding_txid is None:
|
||||
lnaddr = lndecode(invoice)
|
||||
while swap.funding_txid is None and not lnaddr.is_expired():
|
||||
await asyncio.sleep(0.1)
|
||||
else:
|
||||
# broadcast funding tx right away
|
||||
|
||||
Reference in New Issue
Block a user