Skip to content

feat: add Escrow Mongoose schema#83

Open
Olorunfemi20 wants to merge 1 commit into
SwiftChainn:mainfrom
Olorunfemi20:feat/escrow-schema
Open

feat: add Escrow Mongoose schema#83
Olorunfemi20 wants to merge 1 commit into
SwiftChainn:mainfrom
Olorunfemi20:feat/escrow-schema

Conversation

@Olorunfemi20

Copy link
Copy Markdown

Closes #37

Summary

Adds the Escrow Mongoose model used to track funds locked in a Soroban
escrow contract for a delivery.

  • contractId — deployed Soroban contract id (unique)
  • amount / asset — escrowed value and asset code
  • lockStatus — pending | locked | released | refunded
  • delivery — ObjectId reference to the Delivery document
  • transactions[] — append-only log of associated on-chain transaction
    hashes, each with a type (fund/release/refund), ledger number, and
    timestamp
  • timestamps: true for createdAt/updatedAt

A unique index on contractId and a sparse unique index on
transactions.hash prevent duplicate escrow records and duplicate
transaction ingestion (the latter matters once an indexer is polling
the chain and could otherwise reprocess the same event).

Work done

  • New file: src/models/Escrow.ts
  • New tests: tests/escrow.model.test.ts — validation, defaults,
    duplicate contractId rejection, duplicate transaction hash rejection,
    negative amount rejection, required-field enforcement

Test plan

  • npx jest tests/escrow.model.test.ts — 6 passed
  • npx tsc --noEmit — no new type errors
  • npx eslint src/models/Escrow.ts tests/escrow.model.test.ts — clean

Notes for reviewers

This PR is scoped strictly to the schema per the issue's implementation
directory. The Controller/Service/API layers that read and write this
model are introduced in the escrow_funded indexer work (#38), which
depends on this schema.

Add an Escrow model to track funds locked in Soroban escrow contracts
per delivery. The schema records the on-chain contract id, amount,
asset, lock status lifecycle (pending, locked, released, refunded),
and an append-only list of associated transaction hashes with type
and ledger metadata.

A unique index on contractId prevents duplicate escrow records, and a
sparse unique index on transactions.hash guards against an indexer
recording the same on-chain transaction twice.

Covered by tests/escrow.model.test.ts using mongodb-memory-server
against a real in-process MongoDB instance.
@drips-wave

drips-wave Bot commented Jul 26, 2026

Copy link
Copy Markdown

@Olorunfemi20 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: Design Escrow Mongoose Schema

1 participant