-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.sh
More file actions
executable file
·61 lines (53 loc) · 1.78 KB
/
cli.sh
File metadata and controls
executable file
·61 lines (53 loc) · 1.78 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
#!/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"
}
if [[ "${1:-}" == "--block" ]]; then
# Block mode: cli.sh --block <blk> <rev> <xor> [--verbose]
if [[ $# -lt 4 ]]; then
error_json "INVALID_ARGS" "Usage: cli.sh --block <blk_file> <rev_file> <xor_file> [--verbose]"
echo "Error: Missing block arguments" >&2
exit 1
fi
# Pass all remaining args to python
python -m chainlens.cli "${@}"
exit $?
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
mkdir -p out
# Run the Python CLI
python -m chainlens.cli "$FIXTURE"