11#! /usr/bin/env bash
22
3+ # Check bash version (need 4.0+ for associative arrays)
4+ if [ " ${BASH_VERSINFO[0]} " -lt 4 ]; then
5+ echo " ERROR: This script requires Bash 4.0 or higher (you have ${BASH_VERSION} )"
6+ echo " "
7+ echo " On macOS, install a newer bash with:"
8+ echo " brew install bash"
9+ echo " "
10+ echo " Then run the script explicitly with the newer bash:"
11+ echo " /opt/homebrew/bin/bash demo.sh # for Apple Silicon"
12+ echo " /usr/local/bin/bash demo.sh # for Intel Mac"
13+ exit 1
14+ fi
15+
316# variables
417CONTRACT_DIR=" contracts"
518DEBUG=0
@@ -19,7 +32,7 @@ export SEED_PASSWORD="seed test password"
1932BP_WALLET_FEATURES=" --features=cli,hot"
2033BP_WALLET_VER=" 0.12.0-rc.1"
2134RGB_WALLET_FEATURES=" "
22- RGB_WALLET_VER=" 0.12.0-rc.1.1 "
35+ RGB_WALLET_VER=" 0.12.0-rc.3 "
2336
2437# RGB wallet types
2538WALLET_TYPES=(" wpkh" " tapret-key-only" )
@@ -117,7 +130,7 @@ _wait_indexers_sync() {
117130 electrum_json=" {\" jsonrpc\" : \" 2.0\" , \" wallet_type\" : \" blockchain.block.header\" , \" params\" : [$block_count ], \" id\" : 0}"
118131 while : ; do
119132 electrum_res=" $( echo " $electrum_json " \
120- | netcat -w1 localhost $ELECTRUM_PORT \
133+ | nc -w1 localhost $ELECTRUM_PORT \
121134 | jq ' .result' ) "
122135 [ -n " $electrum_res " ] && break
123136 echo -n " ."
@@ -198,12 +211,16 @@ _show_state() {
198211# helper functions
199212check_tools () {
200213 _subtit " checking required tools"
201- local required_tools=" awk base64 cargo cut docker grep head jq netcat sha256sum tr"
214+ local required_tools=" awk base64 cargo cut docker grep head jq sha256sum tr"
202215 for tool in $required_tools ; do
203216 if ! which " $tool " > /dev/null; then
204- _die " could not find reruired tool \" $tool \" , please install it and try again"
217+ _die " could not find required tool \" $tool \" , please install it and try again"
205218 fi
206219 done
220+ # Check for netcat (can be 'nc' or 'netcat' depending on system)
221+ if ! which nc > /dev/null && ! which netcat > /dev/null; then
222+ _die " could not find required tool \" netcat\" (or \" nc\" ), please install it and try again"
223+ fi
207224 if ! docker compose > /dev/null; then
208225 _die " could not call docker compose (hint: install docker compose plugin)"
209226 fi
@@ -225,6 +242,16 @@ install_rust_crate() {
225242 local features opts
226243 local debug=" "
227244 local force=" "
245+
246+ # Check if binary already exists and skip if not forcing recompile
247+ if [ -d " ./$crate /bin" ] && [ $RECOMPILE != 1 ]; then
248+ local bin_count=$( ls " ./$crate /bin" 2> /dev/null | wc -l)
249+ if [ " $bin_count " -gt 0 ]; then
250+ _subtit " skipping $crate installation (binary already exists)"
251+ return 0
252+ fi
253+ fi
254+
228255 if [ -n " $3 " ]; then
229256 read -r -a features <<< " $3"
230257 fi
@@ -263,9 +290,9 @@ set_aliases() {
263290stop_services () {
264291 _subtit " stopping services"
265292 # cleanly stop esplora
266- if $COMPOSE ps | grep -q esplora; then
293+ if docker compose ps | grep -q esplora; then
267294 for SRV in socat electrs; do
268- $COMPOSE exec esplora bash -c " sv -w 60 force-stop /etc/service/$SRV "
295+ docker compose exec esplora bash -c " sv -w 60 force-stop /etc/service/$SRV "
269296 done
270297
271298 fi
@@ -277,7 +304,8 @@ start_services() {
277304 _subtit " checking data directories"
278305 for data_dir in data0 data1 data2; do
279306 if [ -d " $data_dir " ]; then
280- if [ " $( stat -c %u $data_dir ) " = " 0" ]; then
307+ # macOS uses 'stat -f %u' instead of 'stat -c %u'
308+ if [ " $( stat -f %u $data_dir 2> /dev/null || stat -c %u $data_dir 2> /dev/null) " = " 0" ]; then
281309 echo " existing data directory \" $data_dir \" found, owned by root"
282310 echo " please remove it and try again (e.g. 'sudo rm -r $data_dir ')"
283311 _die " cannot continue"
@@ -293,7 +321,7 @@ start_services() {
293321 [ " $PROFILE " = " electrum" ] && EXPOSED_PORTS=(50001)
294322 [ " $PROFILE " = " esplora" ] && EXPOSED_PORTS=(8094)
295323 for port in " ${EXPOSED_PORTS[@]} " ; do
296- if netcat -z localhost " $port " ; then
324+ if nc -z localhost " $port " ; then
297325 _die " port $port is already bound, services can't be started"
298326 fi
299327 done
@@ -421,8 +449,9 @@ issue_contract() {
421449 -e " s/txid/$TXID_ISSUE /" \
422450 -e " s/vout/$VOUT_ISSUE /" \
423451 " $contract_tmpl " > " $contract_yaml "
424- _subtit " issuing"
425- _trace " ${RGB[@]} " -d " data${wallet_id} " import issuers/*
452+ _subtit " importing issuer files (contract type definitions)"
453+ _trace " ${RGB[@]} " -d " data${wallet_id} " import issuers/* .issuer
454+ _subtit " issuing contract from YAML"
426455 _trace " ${RGB[@]} " -d " data${wallet_id} " issue -w " $wallet " " $contract_yaml " \
427456 > $TRACE_OUT 2>&1
428457 issuance=" $( cat $TRACE_OUT ) "
@@ -459,7 +488,7 @@ prepare_rgb_wallet() {
459488 _trace " ${BPHOT[@]} " seed " $WALLET_PATH /$wallet .seed"
460489 _trace " ${BPHOT[@]} " derive -N -s $der_scheme \
461490 " $WALLET_PATH /$wallet .seed" " $WALLET_PATH /$wallet .derive" > $TRACE_OUT
462- account=" $( cat $TRACE_OUT | awk ' /Account/ {print $NF }' ) "
491+ account=" $( cat $TRACE_OUT | awk ' /Account: / {print $2 }' ) "
463492 DESC_MAP[$wallet ]=" $account /<0;1>/*"
464493 [ $DEBUG = 1 ] && echo " descriptor: ${DESC_MAP[$wallet]} "
465494 WALLETS+=(" $wallet " )
@@ -468,8 +497,13 @@ prepare_rgb_wallet() {
468497 # RGB setup
469498 _subtit " creating RGB wallet $wallet "
470499 wallet_id=${WLT_ID_MAP[$wallet]}
471- _trace " ${RGB[@]} " -d " data${wallet_id} " init -q
500+ _trace " ${RGB[@]} " -d " data${wallet_id} " init
472501 _trace " ${RGB[@]} " -d " data${wallet_id} " create --" $wallet_type " " $wallet " " ${DESC_MAP[$wallet]} "
502+ # RGB v0.12 stores wallets as NAME.wallet directories, but accepts NAME in commands
503+ # Rename the directory if needed for compatibility
504+ if [ -d " data${wallet_id} /bitcoin.testnet/$wallet " ] && [ ! -d " data${wallet_id} /bitcoin.testnet/$wallet .wallet" ]; then
505+ mv " data${wallet_id} /bitcoin.testnet/$wallet " " data${wallet_id} /bitcoin.testnet/$wallet .wallet"
506+ fi
473507}
474508
475509sign_and_broadcast () {
@@ -573,7 +607,7 @@ transfer_create() {
573607 local fee=()
574608 [ -n " $SATS " ] && sats=(--sats " $SATS " )
575609 [ -n " $FEE " ] && fee=(--fee " $FEE " )
576- _trace " ${RGB[@]} " -d " $send_data " pay -w " $SEND_WLT " \
610+ _trace " ${RGB[@]} " -d " $send_data " pay " $INDEXER_CLI " -w " $SEND_WLT " \
577611 " ${sats[@]} " " ${fee[@]} " --force \
578612 " $INVOICE " " $send_data /$CONSIGNMENT " " $send_data /$PSBT "
579613 if ! ls " $send_data /$CONSIGNMENT " > /dev/null 2>&1 ; then
@@ -728,8 +762,8 @@ set_aliases
728762trap cleanup EXIT
729763
730764# install crates
731- install_rust_crate " bp-wallet" " $BP_WALLET_VER " " $BP_WALLET_FEATURES " " --git https://github.com/BP-WG/bp-wallet --branch v0.12" # commit 0d439062
732- install_rust_crate " rgb-wallet" " $RGB_WALLET_VER " " $RGB_WALLET_FEATURES " " --git https://github.com/RGB-WG/rgb --branch v0.12 " # commit 9ffff7fb
765+ install_rust_crate " bp-wallet" " $BP_WALLET_VER " " $BP_WALLET_FEATURES " " --git https://github.com/BP-WG/bp-wallet --branch v0.12"
766+ install_rust_crate " rgb-wallet" " $RGB_WALLET_VER " " $RGB_WALLET_FEATURES " " --git https://github.com/RGB-WG/rgb --rev b8c85817c8f1e3336c25dff7e328dff0121722fe "
733767
734768mkdir " $CONTRACT_DIR "
735769
0 commit comments