Add dispute lifecycle endpoints and related utilities#545
Merged
1nonlypiece merged 2 commits intoMay 29, 2026
Merged
Conversation
|
@teethaking is attempting to deploy a commit to the 1nonly's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@nonchalanttee22-lgtm Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #445
PR Description
feat: add dispute lifecycle endpoints (
dispute&resolve-dispute) — closes #445Summary
The escrow contract under
contracts/escrowexposesdisputeandresolve_disputeinstructions, but the backend had no routes wired to them. This PR adds two new API endpoints undersrc/app/api/commitments/[id]/, the corresponding service methods insrc/lib/backend/services/contracts.ts, admin-gated auth on resolution, audit log entries for both actions, Zod-validated request bodies, and full test coverage.What changed
New routes
src/app/api/commitments/[id]/dispute/route.ts—POSTAllows a commitment party to open a dispute against an active escrow.
src/app/api/commitments/[id]/dispute/resolve/route.ts—POSTAdmin-only endpoint to resolve an open dispute. Gated behind
requireAuthwith anadminrole check.Service layer (
src/lib/backend/services/contracts.ts)Two new methods added:
Each method calls the corresponding Soroban contract instruction via the existing RPC client pattern and returns a typed result.
Audit log (
src/lib/backend/auditLog.ts)Both actions write to the audit log:
dispute.opened— recordscommitmentId,caller,reason, timestampdispute.resolved— recordscommitmentId,admin,resolution, timestampZod schemas (colocated in each route file)
Invalid bodies return
400with a structured Zod error payload.Auth
requireAuthis applied at the top ofresolve/route.ts. Requests without a valid admin session get401. Non-admin sessions get403. Thedispute/route.tsendpoint requires authentication but no elevated role — any authenticated commitment party may open a dispute.Security headers
Both route handlers wrap their responses in
attachSecurityHeaders()consistent with the existing pattern in the codebase.File changes
API contract
POST /api/commitments/:id/disputeRequest body:
{ "caller": "GADDRESS...", "reason": "Counterparty has not fulfilled their obligation." }Responses:
201— dispute opened, returns{ disputeId, status: "open", txHash }400— invalid body401— unauthenticated404— commitment not found409— dispute already open on this commitmentPOST /api/commitments/:id/dispute/resolveRequest body:
{ "resolution": "release" | "refund" }Responses:
200— dispute resolved, returns{ status: "resolved", resolution, txHash }400— invalid body401— unauthenticated403— not an admin404— commitment or dispute not found409— dispute already resolvedTests
Coverage targets met (≥95%). Tests in
tests/api/dispute.test.tsandtests/api/dispute-resolve.test.tscover:400on missing/invalid fields (both routes)401when unauthenticated (both routes)403when authenticated but not admin (resolve only)404when commitment ID doesn't exist409when a dispute is already open / already resolvedrequireAuthcalled and short-circuits correctly on resolveAll tests use the mock-request helper pattern from
tests/api/helpers.ts— no network requests.Docs
openapi.yamlhas been extended with path definitions for both new routes, including request body schemas, all response codes, and security requirements (bearerAuth).docs/backend-api-reference.mdhas a new Dispute Lifecycle section with endpoint descriptions, example curl commands, and example responses.docs/backend-changelog.mdhas a new entry under the current version noting the addition ofPOST .../disputeandPOST .../dispute/resolveas new routes (non-breaking).How to test locally