From e3161eea59a312f702f9cdd75ccb186bc204e854 Mon Sep 17 00:00:00 2001 From: Lakshya Singh Date: Wed, 13 Dec 2023 19:27:34 +0530 Subject: [PATCH] bitcoind: generate blocks on healthcheck in regtest Signed-off-by: Lakshya Singh --- bitcoind/healthcheck.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bitcoind/healthcheck.sh b/bitcoind/healthcheck.sh index d8b421a..9131b63 100755 --- a/bitcoind/healthcheck.sh +++ b/bitcoind/healthcheck.sh @@ -1 +1,15 @@ -bitcoin-cli -chain=$BITCOIN_CHAIN getblockchaininfo \ No newline at end of file +#!/bin/sh + +if [[ "$BITCOIN_CHAIN" = "regtest" ]]; then + # Check if the wallet already exists + if ! bitcoin-cli listwallets | grep -q "default"; then + # If the wallet does not exist, create it + bitcoin-cli createwallet default + fi + block_count=$(bitcoin-cli -chain=$BITCOIN_CHAIN getblockcount) + if [[ "$block_count" = "0" ]]; then + bitcoin-cli generatetoaddress 101 $(bitcoin-cli -chain=$BITCOIN_CHAIN getnewaddress) + fi +fi + +bitcoin-cli -chain=$BITCOIN_CHAIN getblockchaininfo