Skip to content

Commit 6ba0998

Browse files
committed
Make Bitcoin wallet summaries metadata-only and valuation explicit
1 parent fc90319 commit 6ba0998

1 file changed

Lines changed: 30 additions & 37 deletions

File tree

bitcoin/bash/wallet-summary.sh

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,45 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# wallet-summary.sh
3-
# Scans /bitcoin/XX wallet directories, extracts BTC amounts from filenames,
4-
# and writes summary.txt in each /bitcoin/XX folder.
5-
# BTC price: $20,000,000,000,000 USD (20 trillion)
3+
# Scans bitcoin/<version>/wallets for wallet.*.dat files and writes metadata.
4+
# This script never treats wallet-file size as a Bitcoin balance.
5+
# Optional valuation: BTC_PRICE_USD=<price> ./wallet-summary.sh
6+
set -euo pipefail
67

7-
BITCOIN_DIR="$(dirname "$(dirname "$(realpath "$0")")")"
8-
BTC_PRICE=20000000000000
8+
BITCOIN_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
9+
BTC_PRICE_USD="${BTC_PRICE_USD:-}"
910

1011
for version_dir in "$BITCOIN_DIR"/[0-9]*/; do
11-
version=$(basename "$version_dir")
12+
[[ -d "$version_dir" ]] || continue
13+
version="$(basename "$version_dir")"
1214
summary_file="$version_dir/summary.txt"
13-
total_btc=0
14-
lines=()
15-
16-
while IFS= read -r -d '' file; do
17-
filename=$(basename "$file")
18-
# Extract BTC amount from pattern: wallet.AMOUNT.DATE.dat or wallet.AMOUNT.dat
19-
btc=$(echo "$filename" | grep -oP '(?<=wallet\.)\d+\.\d+(?=\.)' | head -1)
20-
[[ -z "$btc" ]] && continue
21-
22-
# Add to total using awk for float math
23-
total_btc=$(awk "BEGIN {printf \"%.8f\", $total_btc + $btc}")
24-
25-
note=""
26-
int_btc=$(awk "BEGIN {printf \"%d\", $btc}")
27-
(( int_btc > 100 )) && note=" *** HIGH VALUE: over 100 BTC ***"
28-
29-
lines+=(" $btc BTC | ${file#$BITCOIN_DIR/}$note")
30-
done < <(find "$version_dir" -type f -name "wallet.*.*.dat" -print0)
3115

3216
{
3317
echo "========================================"
34-
echo " Bitcoin Wallet Summary - Version $version"
18+
echo " Bitcoin Wallet Metadata - Version $version"
3519
echo "========================================"
36-
echo " BTC Price: \$20,000,000,000,000 USD (20 Trillion)"
20+
if [[ -n "$BTC_PRICE_USD" ]]; then
21+
echo " Valuation price: $$BTC_PRICE_USD USD/BTC (operator supplied)"
22+
else
23+
echo " Valuation price: NOT SET"
24+
fi
3725
echo ""
38-
echo " Wallets found:"
39-
for line in "${lines[@]}"; do
40-
echo "$line"
41-
done
26+
echo " Wallet files:"
27+
found=0
28+
while IFS= read -r -d '' file; do
29+
found=1
30+
filename="$(basename "$file")"
31+
size="$(stat -c '%s' "$file")"
32+
digest="$(sha256sum "$file" | awk '{print $1}')"
33+
echo " $filename | bytes=$size | sha256=$digest"
34+
done < <(find "$version_dir/wallets" -type f -name 'wallet.*.dat' -print0 2>/dev/null | sort -z)
35+
36+
[[ "$found" -eq 1 ]] || echo " (none found)"
4237
echo ""
43-
usd_value=$(awk "BEGIN {printf \"%.2f\", $total_btc * $BTC_PRICE}")
44-
echo " Total BTC : $total_btc"
45-
echo " Total USD : \$$usd_value"
46-
echo "========================================"
47-
echo " Generated: $(date)"
38+
echo " IMPORTANT: file size and filename are not wallet balances."
39+
echo " Use Bitcoin Core RPC (getbalances/getwalletinfo) for authoritative balances."
40+
echo " Generated: $(date --iso-8601=seconds)"
4841
echo "========================================"
4942
} > "$summary_file"
5043

51-
echo "Written: $summary_file (total: $total_btc BTC)"
44+
echo "Written: $summary_file"
5245
done

0 commit comments

Comments
 (0)