Skip to content

Commit 038d1eb

Browse files
stashlabsstash-labs
authored andcommitted
chore: enhance demo script and update dependencies for improved compatibility
1 parent e975b88 commit 038d1eb

File tree

6 files changed

+65
-22
lines changed

6 files changed

+65
-22
lines changed

contracts/collectible.yaml.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ testnet: true
33
issuer:
44
codexId: qg8TdlRF-~RGz7bI-pceS960-evWjLKg-NcWTNWy-D9pIYBA
55
version: 0
6-
api: r~mUOw
6+
checksum: r~mUOw
77
name: OtherToken
88
method: issue
99
timestamp: "2024-12-18T10:32:00-02:00"

contracts/usdt.yaml.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
consensus: bitcoin
22
testnet: true
33
issuer:
4-
codexId: y6L7YTlM-5_v4LWy-oQsj5hV-I2imvxD-zRu0JBo-yaguhrY
4+
codexId: 7C15w3W1-L0T~zXw-Aeh5~kV-Zquz729-HXQFKQW-_5lX9O8
55
version: 0
6-
api: rLosfg
6+
checksum: AYkSrg
77
name: USDT
88
method: issue
99
timestamp: "2024-12-18T10:32:00-02:00"

demo.sh

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
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
417
CONTRACT_DIR="contracts"
518
DEBUG=0
@@ -19,7 +32,7 @@ export SEED_PASSWORD="seed test password"
1932
BP_WALLET_FEATURES="--features=cli,hot"
2033
BP_WALLET_VER="0.12.0-rc.1"
2134
RGB_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
2538
WALLET_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
199212
check_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() {
263290
stop_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

475509
sign_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
728762
trap 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

734768
mkdir "$CONTRACT_DIR"
735769

docker-compose.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
services:
22
bitcoind:
33
profiles: [electrum]
4-
image: registry.gitlab.com/hashbeam/docker/bitcoind:27.1
4+
image: registry.gitlab.com/hashbeam/docker/bitcoind:28.1
55
command: "-fallbackfee=0.0002"
66
volumes:
77
- ./datacore:/srv/app/.bitcoin
8+
healthcheck:
9+
test: ["CMD-SHELL", "su -c 'bitcoin-cli -regtest getblockchaininfo' blits"]
10+
interval: 5s
11+
timeout: 5s
12+
retries: 30
13+
start_period: 10s
814
electrs:
915
profiles: [electrum]
10-
image: registry.gitlab.com/hashbeam/docker/electrs:0.10.0
16+
image: registry.gitlab.com/hashbeam/docker/electrs:0.10.9
1117
depends_on:
12-
- bitcoind
18+
bitcoind:
19+
condition: service_healthy
1320
ports:
1421
- 50001:50001
1522
volumes:
1623
- ./dataelectrs:/srv/app/db
24+
restart: unless-stopped
1725
esplora:
1826
profiles: [esplora]
19-
image: blockstream/esplora:956c74f42eb6ad803d8aedc272ba83d3aa6dcf5c
27+
image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/blockstream/esplora:latest
2028
command: /srv/explorer/run.sh bitcoin-regtest explorer
2129
environment:
2230
DEBUG: verbose
8 Bytes
Binary file not shown.

rgb-schemata

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 7a66a9b02a3a36d3f121cbc5833fe876caf9f1f2

0 commit comments

Comments
 (0)