Feat: add config.ini for blockchain connection settings

This commit is contained in:
LORDBABUINO
2026-02-27 02:55:07 -03:00
parent 374e185ba1
commit b8e4f03695
3 changed files with 77 additions and 10 deletions

View File

@@ -64,7 +64,26 @@ git clone https://github.com/LORDBABUINO/stealth.git
cd stealth
```
### 2. Bootstrap Bitcoin Core (regtest)
### 2. Configure the blockchain connection
Edit `backend/script/config.ini` to match your node:
```ini
[bitcoin]
# Network: regtest | testnet | signet | mainnet
network = regtest
# Path to bitcoin-cli (full path if not on PATH)
cli = bitcoin-cli
# Optional RPC overrides (leave blank to use ~/.bitcoin/bitcoin.conf defaults)
rpchost =
rpcport =
rpcuser =
rpcpassword =
```
### 3. Bootstrap Bitcoin Core (regtest)
```bash
cd backend/script
@@ -73,7 +92,7 @@ cd backend/script
Pass `--fresh` to wipe the chain and start from genesis.
### 3. Generate vulnerable transactions (required before using the app)
### 4. Generate vulnerable transactions (required before using the app)
```bash
python3 reproduce.py
@@ -90,7 +109,7 @@ bitcoin-cli -regtest -rpcwallet=alice listdescriptors | python3 -c \
Copy the output and use it as the descriptor in the application.
### 4. Start the backend
### 5. Start the backend
```bash
cd backend/src/StealthBackend
@@ -99,7 +118,7 @@ cd backend/src/StealthBackend
The API will be available at `http://localhost:8080`.
### 5. Start the frontend
### 6. Start the frontend
```bash
cd frontend
@@ -123,7 +142,7 @@ Open `http://localhost:5173` in your browser.
stealth/
├── frontend/ # React + Vite UI
├── backend/
│ ├── script/ # detect.py, reproduce.py, setup.sh, bitcoin_rpc.py
│ ├── script/ # detect.py, reproduce.py, setup.sh, bitcoin_rpc.py, config.ini
│ └── src/ # Quarkus Java REST API
└── slides/ # Slidev pitch presentation
```

View File

@@ -1,19 +1,54 @@
"""
bitcoin_rpc.py — Thin wrapper around bitcoin-cli for Python tests.
Uses subprocess calls to bitcoin-cli -regtest.
Connection settings are read from config.ini in the same directory.
"""
import json
import subprocess
import time
import os
import configparser
CLI = "bitcoin-cli"
SIGNET_ARGS = [CLI, "-regtest"]
# ── Load config ──────────────────────────────────────────────────────────────
def _load_config():
cfg = configparser.ConfigParser()
config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "config.ini")
cfg.read(config_path)
return cfg["bitcoin"] if "bitcoin" in cfg else {}
def _build_base_args(section):
cli_bin = section.get("cli", "bitcoin-cli")
network = section.get("network", "regtest").strip().lower()
args = [cli_bin]
network_flags = {
"regtest": "-regtest",
"testnet": "-testnet",
"signet": "-signet",
}
if network in network_flags:
args.append(network_flags[network])
for key, flag in [("rpchost", "-rpcconnect"), ("rpcport", "-rpcport"),
("rpcuser", "-rpcuser"), ("rpcpassword", "-rpcpassword")]:
value = section.get(key, "").strip()
if value:
args.append(f"{flag}={value}")
return args
_cfg = _load_config()
_BASE_ARGS = _build_base_args(_cfg)
# Keep these for any scripts that might reference them directly
CLI = _cfg.get("cli", "bitcoin-cli")
SIGNET_ARGS = _BASE_ARGS
def cli(*args, wallet=None):
"""Call bitcoin-cli -regtest [wallet] <args> and return parsed JSON or string."""
cmd = list(SIGNET_ARGS)
"""Call bitcoin-cli [network] [wallet] <args> and return parsed JSON or string."""
cmd = list(_BASE_ARGS)
if wallet:
cmd.append(f"-rpcwallet={wallet}")
cmd.extend(str(a) for a in args)

13
backend/script/config.ini Normal file
View File

@@ -0,0 +1,13 @@
[bitcoin]
# Network to connect to: regtest | testnet | signet | mainnet
network = regtest
# Path to the bitcoin-cli binary (use full path if not on PATH)
cli = bitcoin-cli
# Optional: override RPC connection details.
# Leave these blank to use the defaults from ~/.bitcoin/bitcoin.conf.
rpchost =
rpcport =
rpcuser =
rpcpassword =