mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-03 20:35:13 +00:00
lnwatcher: use generic callbacks
This commit is contained in:
parent
7da8c2dfe5
commit
782f9ed273
1 changed files with 13 additions and 7 deletions
|
@ -138,7 +138,7 @@ class LNWatcher(AddressSynchronizer):
|
|||
def __init__(self, network: 'Network'):
|
||||
AddressSynchronizer.__init__(self, WalletDB({}, manual_upgrades=False))
|
||||
self.config = network.config
|
||||
self.channels = {}
|
||||
self.callbacks = {} # address -> lambda: coroutine
|
||||
self.network = network
|
||||
util.register_callback(
|
||||
self.on_network_update,
|
||||
|
@ -157,12 +157,19 @@ class LNWatcher(AddressSynchronizer):
|
|||
def add_channel(self, outpoint: str, address: str) -> None:
|
||||
assert isinstance(outpoint, str)
|
||||
assert isinstance(address, str)
|
||||
self.add_address(address)
|
||||
self.channels[address] = outpoint
|
||||
cb = lambda: self.check_onchain_situation(address, outpoint)
|
||||
self.add_callback(address, cb)
|
||||
|
||||
async def unwatch_channel(self, address, funding_outpoint):
|
||||
self.logger.info(f'unwatching {funding_outpoint}')
|
||||
self.channels.pop(address, None)
|
||||
self.remove_callback(address)
|
||||
|
||||
def remove_callback(self, address):
|
||||
self.callbacks.pop(address, None)
|
||||
|
||||
def add_callback(self, address, callback):
|
||||
self.add_address(address)
|
||||
self.callbacks[address] = callback
|
||||
|
||||
@log_exceptions
|
||||
async def on_network_update(self, event, *args):
|
||||
|
@ -172,9 +179,8 @@ class LNWatcher(AddressSynchronizer):
|
|||
if not self.synchronizer:
|
||||
self.logger.info("synchronizer not set yet")
|
||||
return
|
||||
channels_items = list(self.channels.items()) # copy
|
||||
for address, outpoint in channels_items:
|
||||
await self.check_onchain_situation(address, outpoint)
|
||||
for address, callback in list(self.callbacks.items()):
|
||||
await callback()
|
||||
|
||||
async def check_onchain_situation(self, address, funding_outpoint):
|
||||
# early return if address has not been added yet
|
||||
|
|
Loading…
Add table
Reference in a new issue