add regtest setup

This commit is contained in:
f321x
2024-07-15 16:18:36 +02:00
parent 874834f454
commit ba52828f61
6 changed files with 86 additions and 13 deletions

View File

@ -0,0 +1,9 @@
FROM dobtc/bitcoin
COPY ./bitcoin.conf /home/bitcoin/.bitcoin/bitcoin.conf
WORKDIR /home/bitcoin
COPY ./mine-blocks.sh ./mine-blocks.sh
RUN chmod +x ./mine-blocks.sh
CMD ["./mine-blocks.sh"]

View File

@ -2,7 +2,7 @@ server=1
txindex=1
# Authentication
rpcauth=XXX:1234
rpcauth=coordinator:29de0441af68213532c84470616d867c$f936baec7d3d5083617d6d898b3a762999e17bf2453244a37e779caf250dc09f
# generator: https://jlopp.github.io/bitcoin-core-rpc-auth-generator/
# Cookie file authentication
rpccookiefile=/home/bitcoin/.bitcoin/.cookie
@ -11,8 +11,8 @@ maxconnections=15
# Set the maximum number of transactions to keep in the memory pool
maxmempool=300
# Run this node on the Bitcoin Test Network. Equivalent to -chain=test
signet=1
[signet]
regtest=1
[regtest]
rpcbind=0.0.0.0
rpcallowip=0.0.0.0/0
rpcport=8332

View File

@ -0,0 +1,25 @@
#!/bin/sh
/entrypoint.sh bitcoind -regtest -daemon
sleep 10;
# List existing wallets
WALLETS=$(bitcoin-cli -regtest -datadir="/home/bitcoin/.bitcoin" listwalletdir)
# Check if "coordinator_wallet" exists in the list of wallets
if echo "$WALLETS" | grep -q "coordinator_wallet"; then
echo "Wallet exists. Loading wallet..."
bitcoin-cli -regtest -datadir="/home/bitcoin/.bitcoin" loadwallet "coordinator_wallet"
else
echo "Wallet does not exist. Creating wallet..."
bitcoin-cli -regtest -datadir="/home/bitcoin/.bitcoin" createwallet "coordinator_wallet"
fi
# Generate initial blocks
bitcoin-cli -regtest -datadir="/home/bitcoin/.bitcoin" -generate 101
# Generate a block every 300 seconds
while true; do
bitcoin-cli -regtest -datadir="/home/bitcoin/.bitcoin" -generate 1
sleep 300
done

View File

@ -0,0 +1,11 @@
services:
bitcoin:
build: ./data
container_name: bitcoin
ports:
- 8332:8332
volumes:
- bitcoin:/home/bitcoin/.bitcoin
volumes:
bitcoin:

View File

@ -0,0 +1,38 @@
#!/bin/bash
# Function to display help message
show_help() {
echo "Usage: $0 [OPTIONS] <bitcoin_address>"
echo
echo "This script generates blocks to a specified Bitcoin address using RPC."
echo
echo "Options:"
echo " -h, --help Show this help message and exit"
echo
echo "Arguments:"
echo " <bitcoin_address> The Bitcoin address to generate blocks to"
echo
echo "Example:"
echo " $0 bcrt1pcc5nx64a9d6rpk5fkvr6v2lnk06cwxqmgpv3894ehgwkeeal2qusjgjrk3"
}
# Check for help option
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
show_help
exit 0
fi
# Check if an address is provided
if [ $# -eq 0 ]; then
echo "Error: Bitcoin address is required."
echo "Use '$0 --help' for more information."
exit 1
fi
# Get the Bitcoin address from command line argument
bitcoin_address="$1"
# Run the curl command with the provided Bitcoin address
curl --data-binary "{\"jsonrpc\":\"1.0\",\"id\":\"curltext\",\"method\":\"generatetoaddress\",\"params\":[101, \"$bitcoin_address\"]}" \
-H 'content-type:text/plain;' \
http://coordinator:test1234@127.0.0.1:8332/

View File

@ -1,10 +0,0 @@
services:
bitcoin:
container_name: bitcoin
image: dobtc/bitcoin
ports:
- 8332:8332
volumes:
- ./bitcoin.conf:/home/bitcoin/.bitcoin/bitcoin.conf
- ./data/:/home/bitcoin/.bitcoin