From 6fd324ec9f3d9e4a30a4b506c344cedb71432ab0 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Thu, 25 Dec 2025 13:13:46 +0200 Subject: [PATCH] refactor: split watched classes into new file --- basicswap/basicswap.py | 32 +------------------------- basicswap/types.py | 51 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 31 deletions(-) create mode 100644 basicswap/types.py diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index c05265b..c1fbfb2 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -72,6 +72,7 @@ from .db_util import remove_expired_data from .http_server import HttpThread from .rpc import escape_rpcauth from .rpc_xmr import make_xmr_rpc2_func +from .types import WatchedTransaction, WatchedScript, WatchedOutput from .ui.app import UIApp from .ui.util import getCoinName from .util import ( @@ -287,37 +288,6 @@ def threadPollChainState(swap_client, coin_type): swap_client.chainstate_delay_event.wait(random.randrange(*poll_delay_range)) -class WatchedOutput: # Watch for spends - __slots__ = ("bid_id", "txid_hex", "vout", "tx_type", "swap_type") - - def __init__(self, bid_id: bytes, txid_hex: str, vout, tx_type, swap_type): - self.bid_id = bid_id - self.txid_hex = txid_hex - self.vout = vout - self.tx_type = tx_type - self.swap_type = swap_type - - -class WatchedScript: # Watch for txns containing outputs - __slots__ = ("bid_id", "script", "tx_type", "swap_type") - - def __init__(self, bid_id: bytes, script: bytes, tx_type, swap_type): - self.bid_id = bid_id - self.script = script - self.tx_type = tx_type - self.swap_type = swap_type - - -class WatchedTransaction: - # TODO - # Watch for presence in mempool (getrawtransaction) - def __init__(self, bid_id: bytes, txid_hex: str, tx_type, swap_type): - self.bid_id = bid_id - self.txid_hex = txid_hex - self.tx_type = tx_type - self.swap_type = swap_type - - class BasicSwap(BaseApp, BSXNetwork, UIApp): ws_server = None protocolInterfaces = { diff --git a/basicswap/types.py b/basicswap/types.py new file mode 100644 index 0000000..720f8d9 --- /dev/null +++ b/basicswap/types.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2025 The Basicswap developers +# Distributed under the MIT software license, see the accompanying +# file LICENSE or http://www.opensource.org/licenses/mit-license.php. + + +class WatchedOutput: # Watch for spends + __slots__ = ("bid_id", "txid_hex", "vout", "tx_type", "swap_type") + + def __init__(self, bid_id: bytes, txid_hex: str, vout, tx_type, swap_type): + self.bid_id = bid_id + self.txid_hex = txid_hex + self.vout = vout + self.tx_type = tx_type + self.swap_type = swap_type + + +class WatchedScript: # Watch for txns containing outputs + __slots__ = ("bid_id", "script", "tx_type", "swap_type") + + def __init__(self, bid_id: bytes, script: bytes, tx_type, swap_type): + self.bid_id = bid_id + self.script = script + self.tx_type = tx_type + self.swap_type = swap_type + + +class WatchedTransaction: + __slots__ = ( + "bid_id", + "coin_type", + "txid_hex", + "tx_type", + "swap_type", + "block_hash", + "depth", + ) + + # TODO + # Watch for presence in mempool (getrawtransaction) + def __init__( + self, bid_id: bytes, coin_type: int, txid_hex: str, tx_type, swap_type + ): + self.bid_id = bid_id + self.coin_type = coin_type + self.txid_hex = txid_hex + self.tx_type = tx_type + self.swap_type = swap_type + self.block_hash = None + self.depth = -1