-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
94 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
NETWORK=regtest # regtest | signet | ||
RPC_PORT=18443 # 18443 (regtest) | 38332 (signet) | ||
WALLET_PASS=walletpass | ||
# btcstaker private key in WIF format | ||
BTCSTAKER_PRIVKEY= | ||
RPC_USER=rpcuser | ||
RPC_PASS=rpcpass | ||
WALLET_PASS=walletpass | ||
WALLET_NAME=default | ||
BTCSTAKER_WALLET_NAME=btcstaker | ||
BTCSTAKER_WALLET_PASS=walletpass | ||
# btcstaker private key in WIF format | ||
BTCSTAKER_PRIVKEY= | ||
ZMQ_SEQUENCE_PORT=29000 | ||
ZMQ_RAWBLOCK_PORT=29001 | ||
ZMQ_RAWTR_PORT=29002 | ||
# only used if BITCOIN_NETWORK=regtest | ||
GENERATE_INTERVAL_SECS=10 | ||
GENERATE_INTERVAL_SECS=600 # 10 minutes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
echo "NETWORK: $NETWORK" | ||
echo "BTCSTAKER_WALLET_NAME: $BTCSTAKER_WALLET_NAME" | ||
|
||
DATA_DIR=/bitcoind/.bitcoin | ||
|
||
if [[ ! -d "${DATA_DIR}/${NETWORK}/wallets/${BTCSTAKER_WALLET_NAME}" ]]; then | ||
echo "Creating a wallet for btcstaker..." | ||
bitcoin-cli -${NETWORK} -rpcuser="$RPC_USER" -rpcpassword="$RPC_PASS" createwallet "$BTCSTAKER_WALLET_NAME" false false "$BTCSTAKER_WALLET_PASS" false false | ||
fi | ||
|
||
echo "Opening ${BTCSTAKER_WALLET_NAME} wallet..." | ||
bitcoin-cli -${NETWORK} -rpcuser="$RPC_USER" -rpcpassword="$RPC_PASS" -rpcwallet="$BTCSTAKER_WALLET_NAME" walletpassphrase "$BTCSTAKER_WALLET_PASS" 10 | ||
echo "Importing the private key to the wallet ${BTCSTAKER_WALLET_NAME} with the label ${BTCSTAKER_WALLET_NAME} without rescan..." | ||
bitcoin-cli -${NETWORK} -rpcuser="$RPC_USER" -rpcpassword="$RPC_PASS" -rpcwallet="$BTCSTAKER_WALLET_NAME" importprivkey "$BTCSTAKER_PRIVKEY" "${BTCSTAKER_WALLET_NAME}" false | ||
|
||
if [[ "$NETWORK" == "regtest" ]]; then | ||
echo "Generating 110 blocks for the first coinbases to mature..." | ||
bitcoin-cli -${NETWORK} -rpcuser="$RPC_USER" -rpcpassword="$RPC_PASS" -rpcwallet="$BTCSTAKER_WALLET_NAME" -generate 110 | ||
|
||
# Waiting for the wallet to catch up. | ||
sleep 5 | ||
echo "Checking balance..." | ||
bitcoin-cli -${NETWORK} -rpcuser="$RPC_USER" -rpcpassword="$RPC_PASS" -rpcwallet="$BTCSTAKER_WALLET_NAME" getbalance | ||
|
||
echo "Getting the imported BTC address for wallet ${BTCSTAKER_WALLET_NAME}..." | ||
BTCSTAKER_ADDR=$(bitcoin-cli -${NETWORK} -rpcuser="$RPC_USER" -rpcpassword="$RPC_PASS" -rpcwallet="$BTCSTAKER_WALLET_NAME" getaddressesbylabel "${BTCSTAKER_WALLET_NAME}" | jq -r 'keys[0]') | ||
echo "Imported BTC address: ${BTCSTAKER_ADDR}" | ||
|
||
if [[ -z "$GENERATE_INTERVAL_SECS" ]]; then | ||
GENERATE_INTERVAL_SECS=600 # 10 minutes | ||
fi | ||
|
||
echo "Starting block generation every $GENERATE_INTERVAL_SECS seconds in the background..." | ||
( | ||
while true; do | ||
bitcoin-cli -${NETWORK} -rpcuser="$RPC_USER" -rpcpassword="$RPC_PASS" -rpcwallet="$BTCSTAKER_WALLET_NAME" -generate 1 | ||
sleep "$GENERATE_INTERVAL_SECS" | ||
done | ||
) & | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
# Load environment variables from .env.bitcoin file | ||
set -a | ||
source "$(pwd)/.env.bitcoin" | ||
set +a | ||
|
||
# Start the bitcoin container | ||
echo "Starting the bitcoin container..." | ||
docker compose -f "$(pwd)/docker/docker-compose-bitcoin.yml" up -d | ||
|
||
# Wait for the bitcoin node to be ready | ||
echo "Waiting for the bitcoin node to be ready..." | ||
sleep 5 | ||
|
||
max_attempts=10 | ||
attempt=0 | ||
while ! docker exec bitcoind bitcoin-cli -${NETWORK} -rpcuser="$RPC_USER" -rpcpassword="$RPC_PASS" getblockchaininfo &>/dev/null; do | ||
sleep 2 | ||
((attempt++)) | ||
if [ $attempt -ge $max_attempts ]; then | ||
echo "Timeout waiting for bitcoin node to be ready." | ||
exit 1 | ||
fi | ||
done | ||
|
||
echo "Bitcoin node is ready!" | ||
echo | ||
|
||
# Setup the wallet | ||
echo "Setting up the wallet..." | ||
docker exec -it bitcoind /setup-wallet.sh | ||
echo "Wallet setup done!" | ||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters