-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.sh
More file actions
executable file
·86 lines (73 loc) · 2.34 KB
/
Copy pathcli.sh
File metadata and controls
executable file
·86 lines (73 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
set -euo pipefail
###############################################################################
# cli.sh — Bitcoin transaction / block analyzer CLI
#
# Usage:
# ./cli.sh <fixture.json> Single-transaction mode
# ./cli.sh --block <blk.dat> <rev.dat> <xor.dat> Block mode
#
# Transaction mode:
# - Reads the fixture JSON (raw_tx + prevouts)
# - Parses the transaction and computes all fields
# - Writes JSON report to out/<txid>.json
# - Prints JSON report to stdout
# - Exits 0 on success, 1 on error
#
# Block mode:
# - Reads blk*.dat, rev*.dat, and xor.dat
# - Parses all blocks and transactions
# - Writes JSON report per block to out/<block_hash>.json
# - Exits 0 on success, 1 on error
###############################################################################
error_json() {
local code="$1"
local message="$2"
printf '{"ok":false,"error":{"code":"%s","message":"%s"}}\n' "$code" "$message"
}
# Resolve bun binary — fall back to well-known install path used by bun.sh/install
if command -v bun &>/dev/null; then
BUN="bun"
elif [[ -x "$HOME/.bun/bin/bun" ]]; then
BUN="$HOME/.bun/bin/bun"
else
error_json "INTERNAL_ERROR" "bun runtime not found; run setup.sh first"
exit 1
fi
# --- Block mode ---
if [[ "${1:-}" == "--block" ]]; then
shift
if [[ $# -lt 3 ]]; then
error_json "INVALID_ARGS" "Block mode requires: --block <blk.dat> <rev.dat> <xor.dat>"
echo "Error: Block mode requires 3 file arguments: <blk.dat> <rev.dat> <xor.dat>" >&2
exit 1
fi
BLK_FILE="$1"
REV_FILE="$2"
XOR_FILE="$3"
for f in "$BLK_FILE" "$REV_FILE" "$XOR_FILE"; do
if [[ ! -f "$f" ]]; then
error_json "FILE_NOT_FOUND" "File not found: $f"
echo "Error: File not found: $f" >&2
exit 1
fi
done
# Create output directory
mkdir -p out
exec "$BUN" run src/cli.ts --block "$BLK_FILE" "$REV_FILE" "$XOR_FILE"
fi
# --- Single-transaction mode ---
if [[ $# -lt 1 ]]; then
error_json "INVALID_ARGS" "Usage: cli.sh <fixture.json> or cli.sh --block <blk> <rev> <xor>"
echo "Error: No fixture file provided" >&2
exit 1
fi
FIXTURE="$1"
if [[ ! -f "$FIXTURE" ]]; then
error_json "FILE_NOT_FOUND" "Fixture file not found: $FIXTURE"
echo "Error: Fixture file not found: $FIXTURE" >&2
exit 1
fi
# Create output directory
mkdir -p out
exec "$BUN" run src/cli.ts "$@"