feat: cashu escrow DB helpers — Cashu foundation CF-4#797
Conversation
Cashu foundation CF-4 (docs/cashu/01-fundamentals.md, section 6): - update_order_cashu_escrow: atomic compare-and-set that persists the three cashu_* columns AND advances the status in one UPDATE guarded by 'WHERE id = ? AND status = ? AND cashu_escrow_locked_at IS NULL' — no lock-without-advance window, replay/race safe; returns whether a row matched. - find_locked_cashu_orders: WHERE cashu_escrow_locked_at IS NOT NULL, deliberately without a status predicate (the CAS advances status in the same write as the lock, so a status filter would skip legitimately locked rows that moved on). Columns already exist on main (20260530120000_cashu_escrow_fields.sql); no schema change. New, unreferenced functions — no behaviour change. Tests: CAS locks once + replay is a no-op preserving the original lock; status mismatch matches zero rows leaving columns untouched; the finder includes locked orders regardless of status (e.g. FiatSent) and excludes unlocked ones. 506 tests pass (503 pre-existing + 3 new).
|
Warning Review limit reached
Next review available in: 53 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
CF-4 of the Cashu foundation (
docs/cashu/01-fundamentals.md§6). Additive query helpers over the already-migratedcashu_*columns; new, unreferenced functions — zero behaviour change. Frozen-contract signatures from §10 of the spec.update_order_cashu_escrow(pool, order_id, mint_url, token, locked_at, expected_status, new_status) -> Result<bool>— atomic compare-and-set: persists the three columns and transitions the status in oneUPDATE … WHERE id = ? AND status = ? AND cashu_escrow_locked_at IS NULL. No lock-without-advance window; a replayed or concurrent submission matches zero rows instead of double-writing.find_locked_cashu_orders(pool)—WHERE cashu_escrow_locked_at IS NOT NULL, deliberately without a status predicate: the CAS advances the status in the same write as the lock, so filtering on a status would skip legitimately locked rows that already moved on (per the spec's design note, incl. the M-1 review fix).No migration ships here — the columns landed on
mainin20260530120000_cashu_escrow_fields.sql.Test plan
cargo fmt --allcargo clippy --all-targets --all-features -- -D warningscargo test— 506 passed (503 pre-existing unmodified + 3 new):NULLFiatSent→ still found) and excludes unlocked onesIndependent Wave-1 PR of the CF-0…CF-5 series (CF-0 #795, CF-1 #796). Remaining: CF-2 (CashuClient/cdk), CF-3 (mint harness), CF-5 (integration, last).