From 022a1bf0e7a45cc733104c19c37178361459a87b Mon Sep 17 00:00:00 2001 From: f321x Date: Fri, 13 Mar 2026 17:59:13 +0100 Subject: [PATCH] swapserver: cli: skip pending swaps in history commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit skip pending swaps in the swapserver history/summary cli commands. They are not relevant and don't contain all required informations yet. Fixes https://github.com/spesmilo/electrum/issues/10521 Fixes https://github.com/spesmilo/electrum/issues/10525 ```  File "/home/electrum/electrum-fork/electrum/daemon.py", line 268, in handle    response['result'] = await f(*params)                         ^^^^^^^^^^^^^^^^  File "/home/electrum/electrum-fork/electrum/daemon.py", line 381, in run_cmdline    result = await func(*args, **kwargs)             ^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/home/electrum/electrum-fork/electrum/commands.py", line 207, in func_wrapper  File "/home/electrum/electrum-fork/electrum/commands.py", line 2349, in func_wrapper    group = parser.add_argument_group('network options')                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/home/electrum/electrum-fork/electrum/plugins/swapserver/__init__.py", line 79, in get_summary    swap_history = await get_history(self)                   ^^^^^^^^^^^^^^^^^^^^^^^  File "/home/electrum/electrum-fork/electrum/commands.py", line 207, in func_wrapper  File "/home/electrum/electrum-fork/electrum/commands.py", line 2349, in func_wrapper    group = parser.add_argument_group('network options')                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/home/electrum/electrum-fork/electrum/plugins/swapserver/__init__.py", line 60, in get_history    'date': swap['date'].strftime("%Y-%m-%d"),            ^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'strftime' ``` --- electrum/plugins/swapserver/__init__.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/electrum/plugins/swapserver/__init__.py b/electrum/plugins/swapserver/__init__.py index d8b1934a5..a67041759 100644 --- a/electrum/plugins/swapserver/__init__.py +++ b/electrum/plugins/swapserver/__init__.py @@ -2,6 +2,7 @@ from typing import TYPE_CHECKING, List from electrum.simple_config import ConfigVar, SimpleConfig from electrum.commands import plugin_command +from electrum.address_synchronizer import TX_HEIGHT_UNCONFIRMED if TYPE_CHECKING: from electrum.commands import Commands @@ -19,7 +20,7 @@ SimpleConfig.SWAPSERVER_ANN_POW_NONCE = ConfigVar('plugins.swapserver.ann_pow_no @plugin_command('wl', plugin_name) async def get_history(self: 'Commands', wallet: 'Abstract_Wallet' = None, plugin = None) -> List[dict]: """ - Get a list of all swaps provided by this swapserver. + Get a list of all confirmed swaps provided by this swapserver. Single elements can potentially cover multiple swaps if transactions have been batched. Example result: @@ -42,12 +43,20 @@ async def get_history(self: 'Commands', wallet: 'Abstract_Wallet' = None, plugin assert wallet.lnworker, "lightning not available" assert wallet.lnworker.swap_manager, "swap manager not available" - full_history = wallet.get_full_history() - swap_group_ids = set( - x['group_id'] for x in wallet.lnworker.swap_manager.get_groups_for_onchain_history().values() - ) + sm = wallet.lnworker.swap_manager + swap_group_ids = set() + for swap in sm._swaps.values(): + group_id = swap.spending_txid if swap.is_reverse else swap.funding_txid + if group_id is None: + continue + if swap.spending_txid is None \ + or wallet.adb.get_tx_height(swap.spending_txid).height() <= TX_HEIGHT_UNCONFIRMED: + # get only final swaps so the history is stable and doesn't include pending swaps + continue + swap_group_ids.add(group_id) swap_history_items = [] + full_history = wallet.get_full_history() for swap_group_id in swap_group_ids: if swap_history_item := full_history.get('group:' + swap_group_id): swap_history_items.append(swap_history_item) @@ -66,7 +75,7 @@ async def get_history(self: 'Commands', wallet: 'Abstract_Wallet' = None, plugin @plugin_command('wl', plugin_name) async def get_summary(self: 'Commands', wallet: 'Abstract_Wallet' = None, plugin = None) -> dict: - """Get a summary of all swaps provided by this swapserver. + """Get a summary of all confirmed swaps provided by this swapserver. Can become incorrect if closed lightning channels have been deleted in this wallet. Example result: