From b036eaf3ebf0d77e22b11c0badcaf9f2fb781cc1 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Mon, 8 Sep 2025 15:01:50 +0000 Subject: [PATCH] lnwatcher: add some type hints --- electrum/address_synchronizer.py | 2 +- electrum/lnwatcher.py | 21 +++++++++++---------- electrum/synchronizer.py | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py index 6183f96ee..1f28c28da 100644 --- a/electrum/address_synchronizer.py +++ b/electrum/address_synchronizer.py @@ -227,7 +227,7 @@ class AddressSynchronizer(Logger, EventListener): self.unregister_callbacks() self.network = None - def add_address(self, address): + def add_address(self, address: str) -> None: if address not in self.db.history: self.db.history[address] = [] if self.synchronizer: diff --git a/electrum/lnwatcher.py b/electrum/lnwatcher.py index 14ee2750f..c86a28432 100644 --- a/electrum/lnwatcher.py +++ b/electrum/lnwatcher.py @@ -2,7 +2,7 @@ # Distributed under the MIT software license, see the accompanying # file LICENCE or http://www.opensource.org/licenses/mit-license.php -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, Optional, Dict, Callable, Awaitable from . import util from .util import TxMinedInfo, BelowDustLimit, NoDynamicFeeEstimates @@ -27,11 +27,9 @@ class LNWatcher(Logger, EventListener): Logger.__init__(self) self.adb = lnworker.wallet.adb self.config = lnworker.config - self.callbacks = {} # address -> lambda function + self.callbacks = {} # type: Dict[str, Callable[[], Awaitable[None]]] # address -> lambda function self.network = None self.register_callbacks() - # status gets populated when we run - self.channel_status = {} self._pending_force_closes = set() def start_network(self, network: 'Network'): @@ -40,18 +38,21 @@ class LNWatcher(Logger, EventListener): def stop(self): self.unregister_callbacks() - def get_channel_status(self, outpoint): - return self.channel_status.get(outpoint, 'unknown') - - def remove_callback(self, address): + def remove_callback(self, address: str) -> None: self.callbacks.pop(address, None) - def add_callback(self, address, callback, *, subscribe=True): + def add_callback( + self, + address: str, + callback: Callable[[], Awaitable[None]], + *, + subscribe: bool = True, + ) -> None: if subscribe: self.adb.add_address(address) self.callbacks[address] = callback - async def trigger_callbacks(self, *, requires_synchronizer=True): + async def trigger_callbacks(self, *, requires_synchronizer: bool = True): if requires_synchronizer and not self.adb.synchronizer: self.logger.info("synchronizer not set yet") return diff --git a/electrum/synchronizer.py b/electrum/synchronizer.py index 3fbdfcddb..696b6638e 100644 --- a/electrum/synchronizer.py +++ b/electrum/synchronizer.py @@ -83,7 +83,7 @@ class SynchronizerBase(NetworkJobOnDefaultServer): # we are being cancelled now self.session.unsubscribe(self.status_queue) - def add(self, addr): + def add(self, addr: str) -> None: if not is_address(addr): raise ValueError(f"invalid bitcoin address {addr}") self._adding_addrs.add(addr) # this lets is_up_to_date already know about addr