-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.sh
More file actions
executable file
·66 lines (57 loc) · 2.24 KB
/
cli.sh
File metadata and controls
executable file
·66 lines (57 loc) · 2.24 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
#!/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
error_json "INVALID_ARGS" "Usage: cli.sh <fixture.json>"
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
# Derive output filename from fixture basename
# e.g. fixtures/basic_change_p2wpkh.json → out/basic_change_p2wpkh.json
FIXTURE_NAME="$(basename "$FIXTURE")"
OUTPUT_FILE="out/$FIXTURE_NAME"
# TODO: Implement your PSBT builder here
# 1. Read fixture JSON (network, utxos, payments, change, fee_rate_sat_vb, rbf, locktime, …)
# 2. Validate inputs defensively (reject malformed fixtures with structured errors)
# 3. Select coins (UTXOs) to cover payments + estimated fee
# 4. Determine change output (skip if dust; handle fee/change interaction)
# 5. Set nSequence and nLockTime per RBF / locktime rules
# 6. Build unsigned PSBT (BIP-174) with witness_utxo / non_witness_utxo metadata
# 7. Emit warnings (HIGH_FEE, DUST_CHANGE, SEND_ALL, RBF_SIGNALING, …)
# 8. Write JSON report to $OUTPUT_FILE
#
# Example:
# python builder.py "$FIXTURE" "$OUTPUT_FILE"
# node builder.js "$FIXTURE" "$OUTPUT_FILE"
# cargo run -- "$FIXTURE" "$OUTPUT_FILE"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
exec "$SCRIPT_DIR/coinsmith-cli" "$FIXTURE" "$OUTPUT_FILE"