-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.sh
More file actions
executable file
·60 lines (50 loc) · 1.77 KB
/
cli.sh
File metadata and controls
executable file
·60 lines (50 loc) · 1.77 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
#!/usr/bin/env bash
set -euo pipefail
###############################################################################
# cli.sh — Coin Smith: PSBT transaction builder CLI
#
# Usage:
# ./cli.sh <fixture.json>
#
# Workflow:
# 1. Read the fixture JSON (UTXOs, payments, change template, fee rate)
# 2. Select coins (inputs) to fund the payments
# 3. Compute fee, change, and construct outputs
# 4. Build an unsigned PSBT (BIP-174)
# 5. Write JSON report to out/<fixture_name>.json
# 6. Exit 0 on success, 1 on error
#
# On error, writes { "ok": false, "error": { "code": "...", "message": "..." } }
# to the output file and exits 1.
###############################################################################
error_json() {
local code="$1"
local message="$2"
printf '{"ok":false,"error":{"code":"%s","message":"%s"}}\n' "$code" "$message"
}
if [[ $# -lt 1 ]]; then
mkdir -p out
error_json "INVALID_ARGS" "Usage: cli.sh <fixture.json>" > out/invalid_args.json
echo "Error: No fixture file provided" >&2
exit 1
fi
FIXTURE="$1"
# Create output directory
mkdir -p out
# Derive output filename from fixture basename
FIXTURE_NAME="$(basename "$FIXTURE")"
OUTPUT_FILE="out/$FIXTURE_NAME"
if [[ ! -f "$FIXTURE" ]]; then
error_json "FILE_NOT_FOUND" "Fixture file not found: $FIXTURE" > "$OUTPUT_FILE"
echo "Error: Fixture file not found: $FIXTURE" >&2
exit 1
fi
# Run prebuilt release binary generated by setup.sh.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CLI_BIN="$SCRIPT_DIR/coin-smith/target/release/cli"
if [[ ! -x "$CLI_BIN" ]]; then
error_json "BINARY_NOT_FOUND" "Missing CLI binary at coin-smith/target/release/cli. Run ./setup.sh first." > "$OUTPUT_FILE"
echo "Error: Missing CLI binary. Run ./setup.sh first." >&2
exit 1
fi
"$CLI_BIN" "$FIXTURE"