Fix get_pending_swaps: use both funding and spending tx heights
Also, do not show closing warnings if we are offline.
This commit is contained in:
@@ -2699,7 +2699,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
||||
warning = ''.join([
|
||||
_("Are you sure you want to close Electrum?"),
|
||||
'\n\n',
|
||||
_("An ongoing operation prevents Electrum from closing:"),
|
||||
_("An ongoing operation requires you to stay online."),
|
||||
'\n',
|
||||
warning
|
||||
])
|
||||
@@ -2734,6 +2734,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
||||
"""Callback that will return a warning string if there are unconfirmed swap funding txs."""
|
||||
if not (self.wallet.has_lightning() and self.wallet.lnworker.swap_manager):
|
||||
return None
|
||||
if not self.network:
|
||||
return None
|
||||
if ongoing_swaps := self.wallet.lnworker.swap_manager.get_pending_swaps():
|
||||
return "".join((
|
||||
f"{str(len(ongoing_swaps))} ",
|
||||
|
||||
@@ -1283,11 +1283,11 @@ class SwapManager(Logger):
|
||||
"""Returns a list of swaps with unconfirmed funding tx (which require us to stay online)."""
|
||||
pending_swaps: List[SwapData] = []
|
||||
for swap in self.swaps.values():
|
||||
if swap.funding_txid and not swap.is_redeemed:
|
||||
# swap is funded but not marked redeemed by _claim_swap
|
||||
if self.lnworker.wallet.adb.get_tx_height(swap.funding_txid).height < 1:
|
||||
# funding TX is not yet confirmed, wallet should not be closed
|
||||
pending_swaps.append(swap)
|
||||
# note: adb.get_tx_height returns TX_HEIGHT_LOCAL if the txid is unknown
|
||||
funding_height = self.lnworker.wallet.adb.get_tx_height(swap.funding_txid).height
|
||||
spending_height = self.lnworker.wallet.adb.get_tx_height(swap.spending_txid).height
|
||||
if funding_height > TX_HEIGHT_LOCAL and spending_height <= TX_HEIGHT_LOCAL:
|
||||
pending_swaps.append(swap)
|
||||
return pending_swaps
|
||||
|
||||
class SwapServerTransport(Logger):
|
||||
|
||||
Reference in New Issue
Block a user