fixup! feat(docs): update README for cli rust crate instructions

This commit is contained in:
Renato Britto
2026-04-09 16:11:38 -03:00
parent 1d0479cc83
commit 41098fc209
4 changed files with 119 additions and 63 deletions

1
.gitignore vendored
View File

@@ -13,4 +13,5 @@ dist/
**/__pycache__/
target/
Cargo.lock
bitcoin.conf
.bitcoin-regtest

View File

@@ -151,12 +151,11 @@ Stealth currently runs **12 detectors** in `stealth-engine`.
### Prerequisites
| Dependency | Version | Purpose |
| -------------- | ------- | --------------- |
| Bitcoin Core | ≥ 26 | Local node |
| Python | ≥ 3.10 | Analysis engine |
| Java | 21 | Backend |
| Node.js + yarn | ≥ 18 | Frontend |
| Dependency | Version | Purpose |
| -------------- | ------- | ----------------- |
| Bitcoin Core | ≥ 26 | Local node |
| Rust toolchain | ≥ 1.56 | CLI + engine |
| Node.js + yarn | ≥ 18 | Frontend |
### 1. Clone the repository
@@ -168,75 +167,30 @@ cargo build
### 2. Configure Bitcoin Core RPC (regtest)
Create a local `bitcoin.conf`:
Copy the example config:
```bash
cat > bitcoin.conf <<'EOF'
regtest=1
server=1
daemon=1
txindex=1
listen=0
[regtest]
rpcbind=127.0.0.1
rpcallowip=127.0.0.1
rpcuser=localuser
rpcpassword=localpass
rpcport=18443
fallbackfee=0.0002
EOF
cp bitcoin.conf.example bitcoin.conf
```
### 3. Start Bitcoin Core
Regtest example:
### 3. Start regtest and fund a wallet
```bash
mkdir -p "$PWD/.bitcoin-regtest"
bitcoind -datadir="$PWD/.bitcoin-regtest" -conf="$PWD/bitcoin.conf" -daemon
./scripts/setup.sh
```
Mainnet example:
This starts `bitcoind` in regtest mode, creates a wallet, mines initial blocks,
and prints the descriptor and a ready-to-use `stealth-cli` command.
Use `./scripts/setup.sh --fresh` to wipe the chain and start from genesis.
### 4. Run a CLI scan
```bash
bitcoind -daemon
```
### 4. Run a usable CLI scan request
```bash
DATADIR="$PWD/.bitcoin-regtest"
CONF="$PWD/bitcoin.conf"
RPC="bitcoin-cli -datadir=$DATADIR -conf=$CONF -regtest -rpcport=18443"
mkdir -p "$DATADIR"
if ! $RPC getblockchaininfo >/dev/null 2>&1; then
bitcoind -datadir="$DATADIR" -conf="$CONF" -daemon
fi
for _ in $(seq 1 100); do
if $RPC getblockchaininfo >/dev/null 2>&1; then
break
fi
sleep 0.2
done
WALLET="scanwallet_cli"
if ! $RPC -rpcwallet="$WALLET" getwalletinfo >/dev/null 2>&1; then
$RPC loadwallet "$WALLET" >/dev/null 2>&1 || $RPC createwallet "$WALLET" >/dev/null
fi
DESC="$($RPC -rpcwallet="$WALLET" listdescriptors | \
python3 -c 'import json,sys; d=json.load(sys.stdin)["descriptors"]; print(next(x["desc"] for x in d if x.get("active") and not x.get("internal") and "/0/*" in x["desc"]))')"
TARGET_ADDR="$($RPC deriveaddresses "$DESC" "[0,0]" | \
python3 -c 'import json,sys; print(json.load(sys.stdin)[0])')"
$RPC generatetoaddress 101 "$TARGET_ADDR" >/dev/null
cargo run --bin stealth-cli -- scan \
--descriptor "$DESC" \
--descriptor '<descriptor from setup.sh output>' \
--rpc-url http://127.0.0.1:18443 \
--rpc-user localuser \
--rpc-pass localpass \
--rpc-cookie .bitcoin-regtest/regtest/.cookie \
--format text
```
@@ -278,6 +232,7 @@ stealth/
│ │ └── bitcoin-data/ # Regtest chain data (gitignored)
│ └── src/StealthBackend/ # Quarkus Java REST API (single /api/wallet/scan endpoint)
├── cli/ # stealth-cli
├── scripts/ # Development helper scripts (setup.sh)
└── target/ # Cargo build outputs
```

100
scripts/setup.sh Executable file
View File

@@ -0,0 +1,100 @@
#!/usr/bin/env bash
# =============================================================================
# setup.sh — Bootstrap Bitcoin Core regtest for stealth-cli development
# =============================================================================
# Creates a local regtest environment with a funded wallet, then prints the
# descriptor and a ready-to-use stealth-cli command.
#
# Prerequisites: bitcoind, bitcoin-cli, cargo (Rust toolchain).
#
# Usage:
# ./scripts/setup.sh # keep existing chain state
# ./scripts/setup.sh --fresh # wipe regtest, start from genesis
# =============================================================================
set -euo pipefail
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
CONF="$REPO_DIR/bitcoin.conf"
DATADIR="$REPO_DIR/.bitcoin-regtest"
WALLET="scanwallet_cli"
INITIAL_BLOCKS=101
# ─── Parse args ───────────────────────────────────────────────────────────────
FRESH=0
for arg in "$@"; do
[[ "$arg" == "--fresh" ]] && FRESH=1
done
# ─── Ensure bitcoin.conf exists ──────────────────────────────────────────────
if [[ ! -f "$CONF" ]]; then
if [[ -f "$REPO_DIR/bitcoin.conf.example" ]]; then
cp "$REPO_DIR/bitcoin.conf.example" "$CONF"
echo "Copied bitcoin.conf.example → bitcoin.conf"
else
echo "error: bitcoin.conf not found (copy bitcoin.conf.example first)" >&2
exit 1
fi
fi
# ─── Helpers ──────────────────────────────────────────────────────────────────
bcli() { bitcoin-cli -datadir="$DATADIR" -conf="$CONF" -regtest -rpcport=18443 "$@"; }
# ─── Optionally wipe regtest chain ───────────────────────────────────────────
if [[ $FRESH -eq 1 ]]; then
bcli stop 2>/dev/null || true
sleep 2
rm -rf "$DATADIR"
echo "Wiped regtest data"
fi
# ─── Start bitcoind if not running ───────────────────────────────────────────
mkdir -p "$DATADIR"
if ! bcli getblockchaininfo >/dev/null 2>&1; then
bitcoind -datadir="$DATADIR" -conf="$CONF" -daemon
echo -n "Waiting for bitcoind"
for _ in $(seq 1 60); do
if bcli getblockchaininfo >/dev/null 2>&1; then
echo " ready"
break
fi
echo -n "."
sleep 0.5
done
fi
# ─── Create / load wallet ────────────────────────────────────────────────────
if ! bcli -rpcwallet="$WALLET" getwalletinfo >/dev/null 2>&1; then
bcli loadwallet "$WALLET" >/dev/null 2>&1 || bcli createwallet "$WALLET" >/dev/null
fi
# ─── Mine initial blocks ─────────────────────────────────────────────────────
BLOCKS=$(bcli getblockcount)
if [[ $BLOCKS -lt $INITIAL_BLOCKS ]]; then
NEED=$(( INITIAL_BLOCKS - BLOCKS ))
ADDR=$(bcli -rpcwallet="$WALLET" getnewaddress "" bech32)
bcli generatetoaddress "$NEED" "$ADDR" >/dev/null
echo "Mined $NEED blocks (now at $(bcli getblockcount))"
fi
# ─── Print descriptor for stealth-cli ─────────────────────────────────────────
DESC=$(bcli -rpcwallet="$WALLET" listdescriptors \
| grep -o '"desc":"[^"]*"' \
| grep '/0/\*' \
| grep -v 'internal' \
| head -1 \
| sed 's/"desc":"//;s/"$//')
COOKIE="$DATADIR/regtest/.cookie"
echo ""
echo "Regtest ready."
echo ""
echo "Descriptor:"
echo " $DESC"
echo ""
echo "Run:"
echo " cargo run --bin stealth-cli -- scan \\"
echo " --descriptor '$DESC' \\"
echo " --rpc-url http://127.0.0.1:18443 \\"
echo " --rpc-cookie '$COOKIE' \\"
echo " --format text"