Skip to content

Feat/indexer escrow funded - #84

Open
Olorunfemi20 wants to merge 2 commits into
SwiftChainn:mainfrom
Olorunfemi20:feat/indexer-escrow-funded
Open

Feat/indexer escrow funded#84
Olorunfemi20 wants to merge 2 commits into
SwiftChainn:mainfrom
Olorunfemi20:feat/indexer-escrow-funded

Conversation

@Olorunfemi20

Copy link
Copy Markdown

Closes #38

Depends on #37 (Escrow schema) — this branch is stacked on
feat/escrow-schema, please merge that first or set it as the base
branch for this PR.

Summary

Implements the indexer handler that syncs escrow funding from the
Stellar Soroban smart contract into MongoDB.

  • src/indexer/escrowHandlers.ts — parses the escrow_funded contract
    event (topics/value) into a typed payload, and a syncEscrowFundedEvents
    helper that polls the configured Soroban RPC node via getEvents for
    new events (Soroban has no push/webhook mechanism).
  • src/services/escrow.service.ts — creates or updates the Escrow
    document, appends the on-chain transaction hash, and updates the
    related Delivery status to funded. Idempotent: replaying an
    already-recorded transaction hash is a no-op.
  • src/controllers/escrow.controller.ts + src/routes/escrow.routes.ts
    — versioned endpoints following the existing controller -> service ->
    model pattern:
    • GET /api/v1/escrow/delivery/:deliveryId
    • GET /api/v1/escrow/contract/:contractId
    • POST /api/v1/escrow/sync (manually trigger an indexer poll)
  • Delivery.status gains a funded value.
  • ESCROW_CONTRACT_ID / ESCROW_FUNDED_EVENT_TOPIC added to config
    and .env.example.

Work done

New: escrowHandlers.ts, escrow.service.ts, escrow.controller.ts,
escrow.routes.ts, config/escrow.ts, escrow.service.test.ts,
escrowHandlers.test.ts.
Modified: models/Delivery.ts (FUNDED status), routes/index.ts (mount
/v1/escrow), .env.example.

Test plan

  • npx jest tests/escrow.service.test.ts tests/escrowHandlers.test.ts
    21 passed, using mongodb-memory-server against a real in-process
    MongoDB instance (no mocked DB) and contract events built with the
    real stellar-sdk XDR encoder rather than hardcoded fixtures
  • npx tsc --noEmit — no new type errors
  • npx eslint on all new files — clean
  • Full existing suite run to confirm no regressions from these changes

Notes for reviewers

The exact field names inside the escrow_funded event data map
(amount, asset, funded_by) are documented assumptions about the
companion SwiftChain_SmartContract's event shape, since that contract's
source isn't in this repo — happy to adjust to match the actual ABI.

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.
Add the escrow_funded indexer handler that syncs escrow funding from
the Stellar Soroban smart contract into MongoDB, built on the Escrow
schema.

- src/indexer/escrowHandlers.ts parses the escrow_funded contract
  event (topics/value) into a typed payload and hands it to the
  service layer. A syncEscrowFundedEvents helper polls the configured
  Soroban RPC node via getEvents for new events on the escrow
  contract, since Soroban has no push/webhook mechanism.
- src/services/escrow.service.ts creates or updates the Escrow
  document for the funded contract, appends the on-chain transaction
  hash, and updates the related Delivery status to funded. Processing
  is idempotent: replaying an already-recorded transaction hash is a
  no-op, so a re-run over an overlapping ledger range is safe.
- src/controllers/escrow.controller.ts and src/routes/escrow.routes.ts
  expose the versioned endpoints GET /api/v1/escrow/delivery/:deliveryId,
  GET /api/v1/escrow/contract/:contractId, and POST /api/v1/escrow/sync
  (manual trigger for the indexer poll), following the existing
  controller -> service -> model layering used elsewhere in the app.
- Delivery.status gains a FUNDED value.
- ESCROW_CONTRACT_ID / ESCROW_FUNDED_EVENT_TOPIC added to config and
  .env.example.

Covered by tests/escrow.service.test.ts and tests/escrowHandlers.test.ts
using mongodb-memory-server against a real in-process MongoDB instance,
with contract events built via the real stellar-sdk XDR encoder rather
than hardcoded fixtures.
@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: Implement indexer handler for escrow_funded event

1 participant