URI: 
       tadd request_force_close command to CLI add regtest for channel backup - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit f16358ec3c60cef07c63257a64315f53e044acb7
   DIR parent bed4ddbcb4f9d2efa8334ebae21550577f83a2eb
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Fri, 12 Mar 2021 16:10:02 +0100
       
       add request_force_close command to CLI
       add regtest for channel backup
       
       Diffstat:
         M electrum/commands.py                |       6 ++++++
         M electrum/tests/regtest.py           |       3 +++
         M electrum/tests/regtest/regtest.sh   |      24 ++++++++++++++++++++++++
       
       3 files changed, 33 insertions(+), 0 deletions(-)
       ---
   DIR diff --git a/electrum/commands.py b/electrum/commands.py
       t@@ -1081,6 +1081,12 @@ class Commands:
                coro = wallet.lnworker.force_close_channel(chan_id) if force else wallet.lnworker.close_channel(chan_id)
                return await coro
        
       +    @command('wn')
       +    async def request_force_close(self, channel_point, wallet: Abstract_Wallet = None):
       +        txid, index = channel_point.split(':')
       +        chan_id, _ = channel_id_from_funding_tx(txid, int(index))
       +        return await wallet.lnworker.request_force_close_from_backup(chan_id)
       +
            @command('w')
            async def export_channel_backup(self, channel_point, wallet: Abstract_Wallet = None):
                txid, index = channel_point.split(':')
   DIR diff --git a/electrum/tests/regtest.py b/electrum/tests/regtest.py
       t@@ -36,6 +36,9 @@ class TestLightning(unittest.TestCase):
        class TestLightningAB(TestLightning):
            agents = ['alice', 'bob']
        
       +    def test_backup(self):
       +        self.run_shell(['backup'])
       +
            def test_breach(self):
                self.run_shell(['breach'])
        
   DIR diff --git a/electrum/tests/regtest/regtest.sh b/electrum/tests/regtest/regtest.sh
       t@@ -133,6 +133,30 @@ if [[ $1 == "breach" ]]; then
        fi
        
        
       +if [[ $1 == "backup" ]]; then
       +    wait_for_balance alice 1
       +    echo "alice opens channel"
       +    bob_node=$($bob nodeid)
       +    channel=$($alice open_channel $bob_node 0.15)
       +    echo "channel point: $channel"
       +    new_blocks 3
       +    wait_until_channel_open alice
       +    backup=$($alice export_channel_backup $channel)
       +    request=$($bob add_lightning_request 0.01 -m "blah" | jq -r ".invoice")
       +    echo "alice pays"
       +    $alice lnpay $request
       +    seed=$($alice getseed)
       +    $alice stop
       +    sleep 2 # FIXME: we should not have to do that..
       +    mv /tmp/alice/regtest/wallets/default_wallet /tmp/alice/regtest/wallets/default_wallet.old
       +    $alice -o restore "$seed"
       +    $alice daemon -d
       +    $alice load_wallet
       +    $alice import_channel_backup $backup
       +    $alice request_force_close $channel
       +fi
       +
       +
        if [[ $1 == "extract_preimage" ]]; then
            # instead of settling bob will broadcast
            $bob enable_htlc_settle false