refactor: split watched classes into new file

This commit is contained in:
tecnovert
2025-12-25 13:13:46 +02:00
parent b6af5ee93d
commit 6fd324ec9f
2 changed files with 52 additions and 31 deletions

View File

@@ -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 = {

51
basicswap/types.py Normal file
View File

@@ -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