--- /dev/null
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+M=3
+N=7
+
+bitcoin_core_start() {
+ log_msg "starting bitcoin core..."
+ bitcoind --daemon &> /dev/null
+}
+
+bitcoin_core_ready() {
+ set +e
+ for i in {1..5}; do
+ bitcoin-cli help &> /dev/null
+ if [[ $? -eq 0 ]]; then
+ set -e
+ log_msg "bitcoin core ready"
+ return
+ fi
+ sleep 2
+ done
+
+ log_error "bitcoin_core start failed"
+ bitcoin_core_stop
+ exit 1
+}
+
+bitcoin_core_stop() {
+ log_msg "stopping bitcoin core..."
+ bitcoin-cli stop &> /dev/null
+ log_msg "bitcoin core stopped"
+}
+
+depends() {
+ detect base64
+ detect bitcoind
+ detect bitcoin-cli
+# detect cryptsetup
+ detect eject
+ detect jq
+# detect mkfs.ext4
+ detect nmcli
+ detect shred
+# detect wipefs
+}
+
+detect() {
+ set +e
+ which "$1" > /dev/null
+ if [[ $? -ne 0 ]]; then
+ log_error "$1: command not found"
+ exit 1
+ fi
+ set -e
+}
+
+log_error() {
+ echo "$@" >&2
+}
+
+log_msg() {
+ echo "$@"
+}
+
+multisig_create() {
+ local DESCRIPTORS="wsh(sortedmulti($M,"
+
+ for((i = 1; i <= $M; i++)); do
+ DESCRIPTORS+=wallet_descriptors $i
+ done
+
+ DESCRIPTORS+="))"
+}
+
+network_off() {
+ echo "turn networking off"
+ exit 1
+}
+
+usage() {
+
+}
+
+wallet_create() {
+ bitcoin-cli -named createwallet wallet_name=\"wallet$1\" descriptors=true
+}
+
+wallet_descriptors() {
+ local DESCRIPTORS=`bitcoin-cli -rpcwallet=wallet$1 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == false)) | map(.desc | ltrimstr("wpkh")) | .[] | split(")") | .[0]'`
+}
+
+wallet_change_descriptors() {
+ local DESCRIPTORS=`bitcoin-cli -rpcwallet=wallet$1 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == true)) | map(.desc | ltrimstr("wpkh")) | .[] | split(")") | .[0]'`
+}
+
+wallet_dump_descriptors() {
+ bitcoin-cli -named -rpcwallet=wallet$1 listdescriptors private=true
+}
+
+wallets() {
+ for((i = 1; i <= $1; i++)); do
+ wallet_create "$i"
+ done
+}
+
+main() {
+ depends
+ bitcoin_core_start
+
+ bitcoin_core_ready
+
+ wallets "$M"
+
+ bitcoin_core_stop
+}
+
+main "$@"
--- /dev/null
+#!/usr/bin/env bash
+
+TEST_DIR=".testdir"
+
+source source.sh
+
+clean_env() {
+ cd ..
+ rm -rf "$TEST_DIR"
+}
+
+setup_env() {
+ mkdir "$TEST_DIR"
+ cd "$TEST_DIR"
+} > /dev/null 2>&1
+
+reset_env() {
+ clean_env
+ setup_env
+}
+
+assert() {
+ if [[ "$1" != "$2" ]]; then
+ echo -e "Expected:\n$1\nResult:\n$2"
+ echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} failed"
+ exit 1
+ fi
+}
+
+test_failed() {
+ echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} failed"
+ exit 1
+}
+
+test_succeeded() {
+ echo "${BASH_SOURCE[1]} succeeded"
+ clean_env
+}