#!/bin/sh # Start Bitcoind in Signet mode /usr/local/bin/bitcoind -signet -daemon -wallet="test" #change wallet name echo "wating for signet bitcoind to start..." while ! /usr/local/bin/bitcoin-cli -signet getconnectioncount 2>/dev/null 1>&2; do echo -n "."; sleep 1; done echo "started" # Generate mew address and keys ADDR=$(/usr/local/bin/bitcoin-cli -signet getnewaddress '' bech32) PRIVKEY=$(/usr/local/bin/bitcoin-cli -signet dumpprivkey $ADDR) PUBKEY=$(/usr/local/bin/bitcoin-cli -signet getaddressinfo $ADDR | jq -r .pubKey) # Calculate script length and keys LENX2=$(printf $PUBKEY | wc -c) LEN=$((LENX2/2)) LENHEX=$(printf '%x\n' $LEN) SCRIPT="51${LENHEX}${PUBKEY}51ae" # Output the generated values cat < $datadir/bitcoin.conf </dev/null 1>&2; do echo -n "."; sleep 1; done echo "Started" # Import the private key to the custom signet node /usr/local/bin/bitcoin-cli -datadir=$datadir importprivkey "$PRIVKEY" # Generate a new address for mining NADDR=$(/usr/local/bin/bitcoin-cli -datadir=$datadir getnewaddress) # Examples from # https://github.com/bitcoin/bitcoin/pull/19937#issuecomment-696419619 # Define neccessary commands and paths MINER="../contrib/signet/miner" GRIND="./bitcoin-util grind" CLI="./bitcoin-cli -datadir=$datadir" # Calibrate to find a suitable nbits value (Note: it is possible to adjust this as you see fit) NBITS=$($MINER calibrate --grind-cmd="$GRIND" --seconds=160) # Generate an address for receiving mining rewards ADDR=$($CLI -signet getnewaddress) # Advanced Block Generation Process # Generate and create a block template. This generates a PSBT, processes it, and submits the block to the Signet network $CLI -signet getblocktemplate '{"rules": ["signet","segwit"]}' \ | $MINER --cli="$CLI" genpsbt --address="$ADDR" \ | $CLI -signet -stdin walletprocesspsbt \ | jq -r .psbt \ | $MINER --cli="$CLI" solvepsbt --grind-cmd="$GRIND" \ | $CLI -signet -stdin submitblock # Optional for continues mining # $MINER --cli="$CLI" generate --grind-cmd="$GRIND" --address="$ADDR" --nbits=$NBITS --ongoing # Stop the custom Signet node ./bitcoin-cli -datadir=$datadir stop