Skip to content

Implement escrow expiry monitor cron job and admin review API - #78

Open
Elizabethxxx wants to merge 1 commit into
SwiftChainn:mainfrom
Elizabethxxx:feat/escrow-expiry-cron
Open

Implement escrow expiry monitor cron job and admin review API#78
Elizabethxxx wants to merge 1 commit into
SwiftChainn:mainfrom
Elizabethxxx:feat/escrow-expiry-cron

Conversation

@Elizabethxxx

Copy link
Copy Markdown

closes #42

Summary

Adds a background cron job that monitors escrow locks for TTL expiry and flags them in the database, plus a versioned admin API to review and resolve flagged escrows.

  • New Escrow model (src/models/Escrow.ts) tracking deliveryId, amount, lockedAt, ttlSeconds, expiresAt, and lifecycle status (locked / expired / resolved / released)
  • escrowService (src/services/escrowService.ts) encapsulates the scan, listing, and resolution logic; retrieval is always from MongoDB, no inline mocks
  • escrowMonitor job (src/jobs/escrowMonitor.ts) uses node-cron on a configurable schedule (ESCROW_MONITOR_CRON, default every 5 minutes) to find locked escrows past their TTL and mark them expired
  • Each flagged batch is stamped with the current Soroban ledger sequence (via the existing sorobanService.getLatestLedger()) for an on-chain-anchored audit trail
  • Admin API, protected by authenticate + requireRole(ADMIN):
    • GET /api/v1/admin/escrows/flagged — paginated list of expired escrows
    • PATCH /api/v1/admin/escrows/:id/resolve — marks a flagged escrow resolved with audit notes
  • Job is started from server.ts on process boot and stopped on graceful shutdown

Architecture

Follows the existing layered pattern: escrowRoutes.ts -> escrowController.ts -> escrowService.ts -> Escrow model, matching the conventions used by adminRoutes/adminController/adminService.

Test plan

  • npx jest tests/escrow.test.ts — 11/11 passing, covering the scan logic (flags expired, ignores active, is idempotent) and the full admin API surface (200/400/401/403/404/409 paths)
  • npx tsc --noEmit — introduces no new TypeScript errors (pre-existing unrelated errors in deliveryController.ts are untouched by this change)
  • npx eslint on all added/changed files — no errors
  • Full npx jest suite — same 4 pre-existing failing suites as on main prior to this branch; no regressions introduced

Adds a scheduled background job that scans escrow locks for TTL expiry
and flags them for admin review, plus a versioned admin API to list
and resolve flagged escrows.

- New Escrow model tracking lock/TTL/expiry state
- escrowService encapsulates the scan, listing, and resolution logic
- node-cron powered job runs on a configurable schedule and stamps the
  current Soroban ledger sequence onto flagged escrows for an
  on-chain-anchored audit trail
- GET /api/v1/admin/escrows/flagged and PATCH /api/v1/admin/escrows/:id/resolve,
  both admin-only
- Tests cover the scan logic and the full admin API surface
@drips-wave

drips-wave Bot commented Jul 26, 2026

Copy link
Copy Markdown

@Elizabethxxx 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! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend: Implement backend cron job to monitor and flag expired escrow locks

1 participant