Skip to content

Instantly share code, notes, and snippets.

@carnhofdaki
Last active October 2, 2020 11:36
Show Gist options
  • Save carnhofdaki/60edef577f637ef2dbf4d244e4e279c2 to your computer and use it in GitHub Desktop.
Save carnhofdaki/60edef577f637ef2dbf4d244e4e279c2 to your computer and use it in GitHub Desktop.
custom-signet 10/2020
#!/bin/sh
cd ~/src/bitcoin/src
./bitcoind -regtest -daemon=1
printf "Waiting for regtest bitcoind to start"
while ! ./bitcoin-cli -regtest getconnectioncount 2>/dev/null 1>&2
do printf .; sleep 1
done; echo
./bitcoin-cli -regtest createwallet default >/dev/null 2>&1
./bitcoin-cli -regtest loadwallet default >/dev/null 2>&1
ADDR=$(./bitcoin-cli -regtest getnewaddress '' bech32)
PRIVKEY=$(./bitcoin-cli -regtest dumpprivkey $ADDR)
PUBKEY=$(./bitcoin-cli -regtest getaddressinfo $ADDR | jq -r .pubkey)
LENX2=$(printf $PUBKEY | wc -c)
LEN=$((LENX2/2))
LENHEX=$(echo "obase=16; $LEN" | bc)
SCRIPT=$(echo 51${LENHEX}${PUBKEY}51ae)
cat <<EOF
ADDR=$ADDR
PRIVKEY=$PRIVKEY
PUBKEY=$PUBKEY
SCRIPT=$SCRIPT
EOF
./bitcoin-cli -regtest stop 2>&1
datadir=$HOME/signet-custom-$$
mkdir $datadir
cat > $datadir/bitcoin.conf <<EOF
signet=1
[signet]
daemon=1
signetchallenge=$SCRIPT
EOF
./bitcoind -datadir=$datadir
printf "Waiting for custom Signet bitcoind to start"
while ! ./bitcoin-cli -datadir=$datadir getconnectioncount 2>/dev/null 1>&2
do printf .; sleep 1
done; echo
./bitcoin-cli -datadir=$datadir createwallet default >/dev/null 2>&1
./bitcoin-cli -datadir=$datadir loadwallet default >/dev/null 2>&1
./bitcoin-cli -datadir=$datadir importprivkey "$PRIVKEY"
NADDR=$(./bitcoin-cli -datadir=$datadir getnewaddress)
# Examples from
# https://github.com/bitcoin/bitcoin/pull/19937#issuecomment-696419619
../contrib/signet/generate.py --cli="./bitcoin-cli -datadir=$datadir" generate 1 --block-time=1 --address="$NADDR" --grind-cmd='./bitcoin-util grind'
#../contrib/signet/generate.py --cli="./bitcoin-cli -datadir=$datadir" generate 1 --block-time=1 --address="$NADDR" --backdate 0
#../contrib/signet/generate.py --cli="./bitcoin-cli -datadir=$datadir" generate 1 --block-time=1 --descriptor="wpkh(...)#..." --secondary
./bitcoin-cli -datadir=$datadir getblocktemplate '{"rules": ["signet","segwit"]}' \
| ../contrib/signet/generate.py --cli="./bitcoin-cli -datadir=$datadir" genpsbt --address="$NADDR" \
| ./bitcoin-cli -datadir=$datadir -stdin walletprocesspsbt
#../contrib/signet/generate.py solvepsbt --grind-cmd='./bitcoin-util grind' | ./bitcoin-cli -datadir=$datadir submitblock
./bitcoin-cli -datadir=$datadir stop
@carnhofdaki
Copy link
Author

I tested it both with kallewoof/bitcoin@5cced1d78 and kallewoof/bitcoin@856b04190 - same result.

@carnhofdaki
Copy link
Author

There is nothing special in Public Signet debug.log so I did not add it here.

@carnhofdaki
Copy link
Author

This gist is for bitcoin/bitcoin#16411

@carnhofdaki
Copy link
Author

Signet IV updated version of this script is available at https://en.bitcoin.it/wiki/Signet:Custom:Script

bitcoin/bitcoin#19937 needs to be merged in master or use that source tree to compile bitcoind

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment