#!/bin/bash # run bitcoind bitcoind --daemonwait sleep 5 # Create wallet if it doesn't exist DATADIR=${DATADIR:-~/.bitcoin/} if ! bitcoin-cli -datadir=$DATADIR listwallets | grep -q "custom_signet"; then echo "Creating wallet custom_signet" bitcoin-cli -datadir=$DATADIR -named createwallet wallet_name="custom_signet" load_on_startup=true descriptors=true fi # Load wallet if not already loaded if ! bitcoin-cli -datadir=$DATADIR listwallets | grep -q "custom_signet"; then bitcoin-cli -datadir=$DATADIR loadwallet custom_signet fi # Import private key if in mining mode (Bitcoin Core 30+ requires descriptor wallets) # The miner needs the private key in the wallet to sign blocks via walletprocesspsbt # IMPORTANT: For signet mining, we need to import as pk() (P2PK) not wpkh() (P2WPKH) # because the SIGNETCHALLENGE uses a P2PK script that must be signed if [[ "$MINERENABLED" == "1" ]]; then PRIVKEY=${PRIVKEY:-$(cat ~/.bitcoin/PRIVKEY.txt)} if [[ -n "$PRIVKEY" ]]; then echo "Importing private key for mining (descriptor wallet)" # Import as pk() for P2PK signing (required for signet challenge) # The signet miner needs to sign transactions to the SIGNETCHALLENGE which is a P2PK script # Note: pk() descriptors cannot be active (must be ranged), but they can still be used for signing DESCRIPTOR_INFO=$(bitcoin-cli -datadir=$DATADIR getdescriptorinfo "pk($PRIVKEY)") CHECKSUM=$(echo "$DESCRIPTOR_INFO" | jq -r '.checksum') # Import descriptor with checksum (required for Bitcoin Core 30+) # The descriptor doesn't need to be active to sign - it just needs to be in the wallet IMPORT_RESULT=$(bitcoin-cli -datadir=$DATADIR importdescriptors "[{\"desc\":\"pk($PRIVKEY)#$CHECKSUM\",\"timestamp\":0,\"internal\":false}]") if echo "$IMPORT_RESULT" | jq -e '.[0].success == true' > /dev/null; then echo "Private key imported successfully into descriptor wallet (P2PK for signet)" else echo "Warning: Private key import may have failed" echo "Import result: $IMPORT_RESULT" fi fi fi echo "get magic" magic=$(cat /root/.bitcoin/signet/debug.log | grep -m1 magic) magic=${magic:(-8)} echo $magic > /root/.bitcoin/MAGIC.txt # if in mining mode if [[ "$MINERENABLED" == "1" ]]; then mine.sh fi