What changed, and why it matters
This commit only adds Python type hints and removes two unused methods/variables. It does not change any runtime behavior, fix a bug, or alter security logic. There is no security relevance.
No action required; this is a non-functional refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds type annotations (str, None, Dict[str, Callable[[], Awaitable[None]]], bool) to add_address, remove_callback, add_callback, trigger_callbacks, and Synchronizer.add. It also removes the unused channel_status dict and the get_channel_status helper from LNWatcher. No functional code paths are modified.
Changed components
electrum/address_synchronizer.pyelectrum/lnwatcher.pyelectrum/synchronizer.pyInspect captured patch +13 / −12
diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py
index 6183f96..1f28c28 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 14ee275..c86a284 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 3fbdfcd..696b663 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
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.