From 12d8ab64514befb6360eba0c4e2a64f478cb18e7 Mon Sep 17 00:00:00 2001 From: Lagrang3 <32647090+Lagrang3@users.noreply.github.com> Date: Tue, 31 Oct 2023 02:27:54 +0000 Subject: [PATCH] Remove error from startup_regtest when loading wallet startup_regtest now checks if wallet directory exists before creating the default wallet, then it will check if wallet is loaded before attempting to load it. This prevents unnecessary errors during the execution of this bash script. [ Squashed fixup: `regtest: restore double quotes on PATH_TO_BITCOIN` -- RR ] --- contrib/startup_regtest.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/contrib/startup_regtest.sh b/contrib/startup_regtest.sh index ba9761311ec5..838baec39591 100755 --- a/contrib/startup_regtest.sh +++ b/contrib/startup_regtest.sh @@ -142,18 +142,25 @@ start_ln() { # Wait for it to start. while ! bitcoin-cli -datadir="$PATH_TO_BITCOIN" -regtest ping 2> /tmp/null; do echo "awaiting bitcoind..." && sleep 1; done - # Kick it out of initialblockdownload if necessary - if bitcoin-cli -datadir="$PATH_TO_BITCOIN" -regtest getblockchaininfo | grep -q 'initialblockdownload.*true'; then - # Modern bitcoind needs createwallet + # Check if default wallet exists + if ! bitcoin-cli -datadir="$PATH_TO_BITCOIN" -regtest listwalletdir | jq -r '.wallets[] | .name' | grep -wqe 'default' ; then + # wallet dir does not exist, create one echo "Making \"default\" bitcoind wallet." bitcoin-cli -datadir="$PATH_TO_BITCOIN" -regtest createwallet default >/dev/null 2>&1 - # But it might already exist, load it - bitcoin-cli -datadir="$PATH_TO_BITCOIN" -regtest loadwallet default + fi + + # Check if default wallet is loaded + if ! bitcoin-cli -datadir="$PATH_TO_BITCOIN" -regtest listwallets | jq -r '.[]' | grep -wqe 'default' ; then + echo "Loading \"default\" bitcoind wallet." + bitcoin-cli -datadir="$PATH_TO_BITCOIN" -regtest loadwallet default >/dev/null 2>&1 + fi + + # Kick it out of initialblockdownload if necessary + if bitcoin-cli -datadir="$PATH_TO_BITCOIN" -regtest getblockchaininfo | grep -q 'initialblockdownload.*true'; then bitcoin-cli -datadir="$PATH_TO_BITCOIN" -regtest generatetoaddress 1 "$(bitcoin-cli -datadir="$PATH_TO_BITCOIN" -regtest getnewaddress)" > /dev/null - else - bitcoin-cli -datadir="$PATH_TO_BITCOIN" -regtest loadwallet default fi - alias bt-cli='bitcoin-cli -datadir=$PATH_TO_BITCOIN -regtest' + + alias bt-cli='bitcoin-cli -datadir="$PATH_TO_BITCOIN" -regtest' if [ -z "$1" ]; then nodes=2