tcommands: "notify" cmd: stop watching addr if called with empty URL - electrum - Electrum Bitcoin wallet
 (HTM) git clone https://git.parazyd.org/electrum
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
       ---
 (DIR) commit e2ae44beb99c8be98a8a978e7e69612534fe4621
 (DIR) parent 54fdb011f99eb19ceaeb6e778c2f117ec074744c
 (HTM) Author: SomberNight <somber.night@protonmail.com>
       Date:   Fri, 24 Apr 2020 15:34:55 +0200
       
       commands: "notify" cmd: stop watching addr if called with empty URL
       
       closes #5881
       
       Diffstat:
         M electrum/commands.py                |      11 ++++++++---
         M electrum/synchronizer.py            |      13 +++++++++++--
       
       2 files changed, 19 insertions(+), 5 deletions(-)
       ---
 (DIR) diff --git a/electrum/commands.py b/electrum/commands.py
       t@@ -898,11 +898,16 @@ class Commands:
                return True
        
            @command('n')
       -    async def notify(self, address: str, URL: str):
       -        """Watch an address. Every time the address changes, a http POST is sent to the URL."""
       +    async def notify(self, address: str, URL: Optional[str]):
       +        """Watch an address. Every time the address changes, a http POST is sent to the URL.
       +        Call with an empty URL to stop watching an address.
       +        """
                if not hasattr(self, "_notifier"):
                    self._notifier = Notifier(self.network)
       -        await self._notifier.start_watching_queue.put((address, URL))
       +        if URL:
       +            await self._notifier.start_watching_addr(address, URL)
       +        else:
       +            await self._notifier.stop_watching_addr(address)
                return True
        
            @command('wn')
 (DIR) diff --git a/electrum/synchronizer.py b/electrum/synchronizer.py
       t@@ -263,7 +263,7 @@ class Notifier(SynchronizerBase):
            def __init__(self, network):
                SynchronizerBase.__init__(self, network)
                self.watched_addresses = defaultdict(list)  # type: Dict[str, List[str]]
       -        self.start_watching_queue = asyncio.Queue()
       +        self._start_watching_queue = asyncio.Queue()  # type: asyncio.Queue[Tuple[str, str]]
        
            async def main(self):
                # resend existing subscriptions if we were restarted
       t@@ -271,11 +271,20 @@ class Notifier(SynchronizerBase):
                    await self._add_address(addr)
                # main loop
                while True:
       -            addr, url = await self.start_watching_queue.get()
       +            addr, url = await self._start_watching_queue.get()
                    self.watched_addresses[addr].append(url)
                    await self._add_address(addr)
        
       +    async def start_watching_addr(self, addr: str, url: str):
       +        await self._start_watching_queue.put((addr, url))
       +
       +    async def stop_watching_addr(self, addr: str):
       +        self.watched_addresses.pop(addr, None)
       +        # TODO blockchain.scripthash.unsubscribe
       +
            async def _on_address_status(self, addr, status):
       +        if addr not in self.watched_addresses:
       +            return
                self.logger.info(f'new status for addr {addr}')
                headers = {'content-type': 'application/json'}
                data = {'address': addr, 'status': status}