Skip to content

Commit 0e532be

Browse files
committed
Add grace period for cli sender
1 parent 0dc6c28 commit 0e532be

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

scripts/payjoin_cli_send_test.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ AMOUNT_SAT="${PAYJOIN_CLI_SEND_AMOUNT_SAT:-2000}"
5353
FEE_RATE="${PAYJOIN_CLI_FEE_RATE:-2}"
5454
BIP21_WAIT_SECS="${BIP21_WAIT_SECS:-180}"
5555
CLI_TIMEOUT_SECS="${CLI_TIMEOUT_SECS:-300}"
56+
CLI_BROADCAST_GRACE_SECS="${CLI_BROADCAST_GRACE_SECS:-60}"
5657

5758
# Pin the Rust toolchain for payjoin-cli builds
5859
export RUSTUP_TOOLCHAIN="$RUST_TOOLCHAIN"
@@ -186,7 +187,7 @@ echo "[script] Final URI: $BIP21_URI"
186187
echo "[script] Starting payjoin-cli send (fee-rate: ${FEE_RATE} sat/vB)..."
187188
echo "[script] Full command: cargo run --manifest-path $CLI_SOURCE_DIR/Cargo.toml -- ${RPC_ARGS[*]} --db-path $DB_PATH --ohttp-relays $OHTTP_RELAY --pj-directory $PJ_DIRECTORY send --fee-rate $FEE_RATE \"$BIP21_URI\""
188189

189-
"$CARGO_PATH" run \
190+
RUST_LOG=trace "$CARGO_PATH" run \
190191
--manifest-path "$CLI_SOURCE_DIR/Cargo.toml" \
191192
-- \
192193
"${RPC_ARGS[@]}" \
@@ -244,6 +245,18 @@ while [ "$ELAPSED" -lt "$CLI_TIMEOUT_SECS" ]; do
244245
fi
245246
fi
246247

248+
# When Flutter finishes first, give the CLI a grace period to complete
249+
# its broadcast (sendrawtransaction RPC) before the loop times out.
250+
if [ "$FLUTTER_DONE" = true ] && [ "$CLI_DONE" = false ]; then
251+
if [ -z "${CLI_GRACE_DEADLINE:-}" ]; then
252+
CLI_GRACE_DEADLINE=$((ELAPSED + CLI_BROADCAST_GRACE_SECS))
253+
echo "[script] Flutter done — giving CLI ${CLI_BROADCAST_GRACE_SECS}s grace period to finish broadcast..."
254+
elif [ "$ELAPSED" -ge "$CLI_GRACE_DEADLINE" ]; then
255+
echo "[script] CLI grace period expired (${CLI_BROADCAST_GRACE_SECS}s) — checking for raw tx in log..."
256+
break
257+
fi
258+
fi
259+
247260
if [ "$FLUTTER_DONE" = true ] && [ "$CLI_DONE" = true ]; then
248261
break
249262
fi
@@ -298,9 +311,7 @@ if [ -s "$CLI_LOG" ]; then
298311
echo " [INFO] CLI mentions success but no txid found in output"
299312
else
300313
echo " [WARN] No broadcast confirmation in CLI output"
301-
if [ "$CLI_EXIT" != "0" ]; then
302-
PASS=false
303-
fi
314+
PASS=false
304315
fi
305316
else
306317
echo " [FAIL] payjoin-cli produced no output (was it started?)"

0 commit comments

Comments
 (0)