Last active
March 2, 2024 05:53
-
-
Save brakmic/37c7618ad6e8bb33c6a271fe682e38a3 to your computer and use it in GitHub Desktop.
Build and run Bitcoin Signet
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
#!/usr/bin/env bash | |
#-----------------------------------------------------------------------------------------------------# | |
# Build and run Bitcoin Signet - developed by Kalle Alm (@kallewoof) # | |
# # | |
# Follow the development on GitHub: https://github.com/bitcoin/bitcoin/pull/18267 # | |
# # | |
# For this script to run you'll have to install several packages first (boost, libevent, libzmq3) # | |
# Check this doc for more info: https://github.com/bitcoin/bitcoin/blob/master/doc/build-unix.md # | |
# # | |
# Script usage: # | |
# # | |
# Save it as 'runsignet.sh', then execute: chmod +x ./runsignet.sh # | |
# Run it with: ./runsignet.sh and wait for it to complete. # | |
# # | |
#------------------------------------------------------------------------------------------------------ | |
# adapt to your root path | |
DISK_ROOT=`pwd` | |
SIGNET_REPO="https://github.com/kallewoof/bitcoin.git" | |
SIGNET_REPO_BRANCH="2003-signet-consensus" | |
SIGNET_CLONE_NAME="signet" | |
SIGNET_DATADIR_NAME="signet_datadir" | |
SIGNET_DATADIR_BACKUP_NAME="signet_datadir_backup" | |
SIGNET_CLONE_ROOT="${DISK_ROOT}/${SIGNET_CLONE_NAME}" | |
SIGNET_DATADIR="${SIGNET_CLONE_ROOT}/src/${SIGNET_DATADIR_NAME}" | |
SIGNET_DATADIR_BACKUP="${DISK_ROOT}/${SIGNET_DATADIR_BACKUP_NAME}" | |
SIGNET_BITCOIND="${SIGNET_CLONE_ROOT}/src/bitcoind" | |
SIGNET_BITCOIN_CLI="${SIGNET_CLONE_ROOT}/src/bitcoin-cli" | |
RPC_USER="user"$(env LC_ALL=C tr -dc 'A-Za-z0-9_!@$%^&*()\-+=' < /dev/urandom | head -c 30) | |
RPC_PWD=$(env LC_ALL=C tr -dc 'A-Za-z0-9_!@$%^&*()\-+=' < /dev/urandom | head -c 30) | |
DEFAULT_BITCOIN_CONF="signet=1\n[signet]\ndaemon=1\nupnp=1\nrest=1\nlisten=1\nrpcuser=${RPC_USER}\nrpcpassword=${RPC_PWD}" | |
MAKE="make" | |
MAKE_FLAGS="-j4" | |
# check for datadir backup | |
# if it doesn't exist, create one with default bitcoin.conf in it | |
if [ ! -d "$SIGNET_DATADIR_BACKUP" ]; then | |
echo "Creating backup datadir ${SIGNET_DATADIR_BACKUP}" | |
mkdir ${SIGNET_DATADIR_BACKUP} | |
mkdir ${SIGNET_DATADIR_BACKUP}/signet | |
mkdir ${SIGNET_DATADIR_BACKUP}/signet/wallets | |
echo "Creating default bitcoin.conf" | |
echo -e ${DEFAULT_BITCOIN_CONF} > ${SIGNET_DATADIR_BACKUP}/bitcoin.conf | |
fi | |
# make backup of existing bitcoin.conf and wallet files | |
if [ -d "$SIGNET_DATADIR" ]; then | |
echo "Copying existing wallet files to ${SIGNET_DATADIR_BACKUP}" | |
cp -rv ${SIGNET_DATADIR}/signet/wallets/* ${SIGNET_DATADIR_BACKUP}/signet/wallets | |
echo "Moving existing bitcoin.conf to ${SIGNET_DATADIR_BACKUP}" | |
mv ${SIGNET_DATADIR}/bitcoin.conf ${SIGNET_DATADIR_BACKUP} | |
fi | |
# remove existing local clone | |
if [ -d "$SIGNET_CLONE_ROOT" ]; then | |
echo "Removing existing ${SIGNET_CLONE_ROOT} source directory." | |
rm -rf ${SIGNET_CLONE_ROOT} | |
fi | |
# get a fresh clone and switch to signet branch | |
echo -e "\n" | |
echo "-----------------------------------" | |
echo " Getting Bitcoin Signet sources " | |
echo "-----------------------------------" | |
echo -e "\n" | |
git clone ${SIGNET_REPO} ${SIGNET_CLONE_NAME} | |
cd ${SIGNET_CLONE_ROOT} | |
git checkout ${SIGNET_REPO_BRANCH} | |
git pull | |
# Raspberry Pi 4 must build BDB4 | |
if [[ "$OSTYPE" == "linux-gnueabihf"* ]]; then | |
# compile and install BDB | |
echo -e "\n" | |
echo "---------------------------" | |
echo " Installing BerkeleyDB 4 " | |
echo "---------------------------" | |
echo -e "\n" | |
BDB_PREFIX="${SIGNET_CLONE_ROOT}/db4" | |
make_bdb() { | |
./contrib/install_db4.sh `pwd` | |
} | |
make_bdb | |
fi | |
# configure and compile signet sources | |
echo -e "\n" | |
echo "-------------------------------------------" | |
echo " Configuring & Compiling Bitcoin Signet " | |
echo "-------------------------------------------" | |
echo -e "\n" | |
BOOST_CONFIG_FLAGS="" | |
GUI_FLAGS="--without-gui" | |
TEST_FLAGS="--disable-tests" | |
BENCH_FLAGS="--disable-bench" | |
SHARED_FLAGS="--disable-shared" | |
if [[ "$OSTYPE" == "linux-gnueabihf"* ]]; then | |
BOOST_CONFIG_FLAGS="--with-boost-libdir=/usr/lib/arm-linux-gnueabihf" | |
fi | |
make_bitcoind() { | |
./autogen.sh | |
./configure "BDB_LIBS='-L${BDB_PREFIX}/lib -ldb_cxx-4.8'" "BDB_CFLAGS='-I${BDB_PREFIX}/include'" "${TEST_FLAGS}" "${BENCH_FLAGS}" "${SHARED_FLAGS}" "${GUI_FLAGS}" "${BOOST_CONFIG_FLAGS}" | |
"${MAKE}" "${MAKE_FLAGS}" | |
} | |
make_bitcoind | |
# copy backup datadir and start Bitcoin Signet daemon | |
echo -e "\n" | |
echo "--------------------------------------------" | |
echo " Setting up Bitcoin Signet Configuration " | |
echo "--------------------------------------------" | |
echo -e "\n" | |
mkdir ${SIGNET_DATADIR} | |
cp -rv ${SIGNET_DATADIR_BACKUP}/* ${SIGNET_DATADIR} | |
echo -e "\n" | |
echo "---------------------------" | |
echo " Starting Bitcoin Signet " | |
echo "---------------------------" | |
echo -e "\n" | |
run_bitcoind() { | |
"${SIGNET_BITCOIND}" "-datadir=${SIGNET_DATADIR}" | |
} | |
run_bitcoind | |
# verify connection | |
echo -e "\n" | |
echo "-------------------------------------" | |
echo " Verifying Bitcoin Signet " | |
echo " Please Wait " | |
echo "-------------------------------------" | |
echo -e "\n" | |
check_connections() { | |
sleep 10s | |
"${SIGNET_BITCOIN_CLI}" "-datadir=${SIGNET_DATADIR}" "getconnectioncount" | |
} | |
conncount=$(check_connections) | |
if [ conncount > 0 ]; then | |
echo "Success!" | |
echo "Active connections: ${conncount}" | |
else | |
echo "Failed!" | |
echo "No connections. Check your local network settings." | |
fi | |
check_blocks() { | |
"${SIGNET_BITCOIN_CLI}" "-datadir=${SIGNET_DATADIR}" "getblockcount" | |
} | |
blockcount=$(check_blocks) | |
if [ blockcount >= 1 ]; then | |
echo "Success!" | |
echo "Block count: ${blockcount}" | |
else | |
echo "Failed!" | |
echo "No blocks. Check your local network settings." | |
fi | |
# get Signet bitcoins | |
echo -e "\n" | |
echo "-------------------------------------------------" | |
echo " Generate new address and get sBTC from faucet " | |
echo "-------------------------------------------------" | |
echo -e "\n" | |
FAUCET_URL=https://signet.bc-2.jp/claim | |
get_address() { | |
"${SIGNET_BITCOIN_CLI}" "-datadir=${SIGNET_DATADIR}" "getnewaddress" | |
} | |
address=$(get_address) | |
address_param="address="${address} | |
echo "Address: "${address} | |
get_coins() { | |
curl "-d" $address_param "-H" "Content-Type: application/x-www-form-urlencoded" "${FAUCET_URL}" | |
} | |
get_coins | |
echo -e "\n" | |
echo "-----------------------------------------------" | |
echo " Have fun with Bitcoin Signet! " | |
echo "-----------------------------------------------" | |
echo -e "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment