Skip to content

Implement real-time invoice status subscriptions using Soroban event streaming #417

Description

@Kingsman-99

Overview

Add a subscribeInvoice(invoiceId, callback) method to StellarSplitClient that opens a long-lived Soroban event stream and fires the callback on every state change for the given invoice. The subscription must handle reconnection, backpressure, and deduplication of events.

Requirements

  • client.subscribeInvoice(invoiceId: bigint, callback: (event: InvoiceEvent) => void): Subscription
  • Subscription type with .unsubscribe() method to cancel the stream
  • Use Soroban getEvents RPC polling with a configurable pollIntervalMs (default 3000ms)
  • Deduplicate events by ledger sequence + topic hash to prevent duplicate callbacks
  • Automatic reconnection with exponential backoff (max 5 retries, then emit error event)
  • Export InvoiceEvent union type covering all contract event types
  • Write unit tests with a mock RPC server using msw (Mock Service Worker)
  • Test: normal event stream, deduplication, reconnect after failure, unsubscribe stops polling

Acceptance Criteria

  • subscribeInvoice implemented and exported from the package
  • Reconnection with exponential backoff working
  • Deduplication verified in tests
  • unsubscribe() stops polling (no memory leaks)
  • All existing tests pass
  • npm test passes with zero failures
  • TypeScript compiles with zero errors (tsc --noEmit)
  • ESLint passes with zero errors

Definition of Done

All CI checks must pass before the PR is reviewed.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions