URI: 
       tcli/rpc: fix 'sweep' command - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit f74ac1a74124a868bd48c75c405cd541d2ca470c
   DIR parent dbb7d7ce4d217b378976f8e29a9ec4aa419bc7a5
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Tue,  8 Dec 2020 12:21:56 +0100
       
       cli/rpc: fix 'sweep' command
       
       fixes #6825
       
       Diffstat:
         M electrum/commands.py                |      14 ++++++++------
         M electrum/tests/test_wallet_vertica… |       7 +++----
         M electrum/wallet.py                  |      16 ++++++++++++----
         M run_electrum                        |       1 +
       
       4 files changed, 24 insertions(+), 14 deletions(-)
       ---
   DIR diff --git a/electrum/commands.py b/electrum/commands.py
       t@@ -566,12 +566,14 @@ class Commands:
                privkeys = privkey.split()
                self.nocheck = nocheck
                #dest = self._resolver(destination)
       -        tx = sweep(privkeys,
       -                   network=self.network,
       -                   config=self.config,
       -                   to_address=destination,
       -                   fee=tx_fee,
       -                   imax=imax)
       +        tx = await sweep(
       +            privkeys,
       +            network=self.network,
       +            config=self.config,
       +            to_address=destination,
       +            fee=tx_fee,
       +            imax=imax,
       +        )
                return tx.serialize() if tx else None
        
            @command('wp')
   DIR diff --git a/electrum/tests/test_wallet_vertical.py b/electrum/tests/test_wallet_vertical.py
       t@@ -1397,9 +1397,6 @@ class TestWalletSending(TestCaseForTestnet):
        
                class NetworkMock:
                    relay_fee = 1000
       -            def run_from_another_thread(self, coro):
       -                loop = asyncio.get_event_loop()
       -                return loop.run_until_complete(coro)
                    async def listunspent_for_scripthash(self, scripthash):
                        if scripthash == '460e4fb540b657d775d84ff4955c9b13bd954c2adc26a6b998331343f85b6a45':
                            return [{'tx_hash': 'ac24de8b58e826f60bd7b9ba31670bdfc3e8aedb2f28d0e91599d741569e3429', 'tx_pos': 1, 'height': 1325785, 'value': 1000000}]
       t@@ -1414,7 +1411,9 @@ class TestWalletSending(TestCaseForTestnet):
                privkeys = ['93NQ7CFbwTPyKDJLXe97jczw33fiLijam2SCZL3Uinz1NSbHrTu', ]
                network = NetworkMock()
                dest_addr = 'tb1q3ws2p0qjk5vrravv065xqlnkckvzcpclk79eu2'
       -        tx = sweep(privkeys, network=network, config=self.config, to_address=dest_addr, fee=5000, locktime=1325785, tx_version=1)
       +        sweep_coro = sweep(privkeys, network=network, config=self.config, to_address=dest_addr, fee=5000, locktime=1325785, tx_version=1)
       +        loop = asyncio.get_event_loop()
       +        tx = loop.run_until_complete(sweep_coro)
        
                tx_copy = tx_from_any(tx.serialize())
                self.assertEqual('010000000129349e5641d79915e9d0282fdbaee8c3df0b6731bab9d70bf626e8588bde24ac010000004847304402206bf0d0a93abae0d5873a62ebf277a5dd2f33837821e8b93e74d04e19d71b578002201a6d729bc159941ef5c4c9e5fe13ece9fc544351ba531b00f68ba549c8b38a9a01fdffffff01b82e0f00000000001600148ba0a0bc12b51831f58c7ea8607e76c5982c071fd93a1400',
   DIR diff --git a/electrum/wallet.py b/electrum/wallet.py
       t@@ -164,10 +164,18 @@ async def sweep_preparations(privkeys, network: 'Network', imax=100):
            return inputs, keypairs
        
        
       -def sweep(privkeys, *, network: 'Network', config: 'SimpleConfig',
       -          to_address: str, fee: int = None, imax=100,
       -          locktime=None, tx_version=None) -> PartialTransaction:
       -    inputs, keypairs = network.run_from_another_thread(sweep_preparations(privkeys, network, imax))
       +async def sweep(
       +        privkeys,
       +        *,
       +        network: 'Network',
       +        config: 'SimpleConfig',
       +        to_address: str,
       +        fee: int = None,
       +        imax=100,
       +        locktime=None,
       +        tx_version=None
       +) -> PartialTransaction:
       +    inputs, keypairs = await sweep_preparations(privkeys, network, imax)
            total = sum(txin.value_sats() for txin in inputs)
            if fee is None:
                outputs = [PartialTxOutput(scriptpubkey=bfh(bitcoin.address_to_script(to_address)),
   DIR diff --git a/run_electrum b/run_electrum
       t@@ -419,6 +419,7 @@ def handle_cmd(*, cmdname: str, config: 'SimpleConfig', config_options: dict):
                    d.run_daemon()
                    sys_exit(0)
                else:
       +            # FIXME this message is lost in detached mode (parent process already exited after forking)
                    print_msg("Daemon already running")
                    sys_exit(1)
            else: