Skip to content

Soroban Contract Event Log Subscriber #544

Description

@Kingsman-99

Description

Soroban smart contracts emit structured events that the SDK consumes but only processes synchronously during transaction result parsing. Long-running processes need to subscribe to a contract's event stream and react to new events (e.g. split_registered, payment_released) as they are emitted on-chain, without polling for each transaction individually. A contract event log subscriber should abstract the getEvents RPC call into a reactive subscription.

Technical Context

Add src/contractEventSubscriber.ts. Uses @stellar/stellar-sdk SorobanRpc.Server.getEvents() with filters: [{ type: 'contract', contractIds: [...] }]. Polls at a configurable interval (default 5 s) and yields only new events since the last startLedger. Adds ContractEventFilter and ParsedContractEvent to src/types.ts. Integrates with src/events.ts and src/cursorTracker.ts for ledger position persistence.

Acceptance Criteria

  • ContractEventSubscriber.subscribe(contractId, filter): AsyncIterableIterator<ParsedContractEvent> yields new contract events as they appear on-chain
  • Parses event topics and data from XDR using @stellar/stellar-sdk xdr.ScVal decode utilities
  • Persists the last-processed ledgerSequence via src/cursorTracker.ts so the subscription resumes correctly after a restart
  • unsubscribe() stops the polling loop and releases resources
  • Unit tests mock SorobanRpc.getEvents() responses across three poll cycles and assert that only new events (not duplicates) are yielded
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions