Skip to content

feat(stellar): abstract Horizon client into HorizonService module - #97

Merged
Wilfred007 merged 1 commit into
Protocol-Guild:mainfrom
Gbangbolaoluwagbemiga:BACKEND-5-horizon-service
Mar 7, 2026
Merged

feat(stellar): abstract Horizon client into HorizonService module#97
Wilfred007 merged 1 commit into
Protocol-Guild:mainfrom
Gbangbolaoluwagbemiga:BACKEND-5-horizon-service

Conversation

@Gbangbolaoluwagbemiga

@Gbangbolaoluwagbemiga Gbangbolaoluwagbemiga commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

This PR abstracts the Stellar Horizon client into a proper service module following the issue requirements.

Changes made:

[NEW] backend/src/stellar/horizonService.ts — Core HorizonService class that handles:

Lazy-cached Horizon.Server instance (created once, reused across calls)
Testnet/Mainnet switching via STELLAR_NETWORK env var (delegates to existing network.ts)
Exponential-backoff retry logic (withRetry()) for transient network errors. Permanent 4xx errors are NOT retried.
Startup health check (checkOnStartup()) which fetches fee stats, logs latency and ledger sequence, and optionally throws if unreachable so the app fails fast
A shared horizonService singleton for convenience alongside a class export for custom-configured instances
[MODIFY] backend/src/stellar/client.ts — Refactored to delegate getStellarServer(), getActiveNetworkConfig(), and resetClient() to the new service. Zero breaking changes for existing callers.

[MODIFY] backend/src/stellar/index.ts — Added HorizonService, horizonService, and HealthCheckResult to the barrel exports.

Closes #5

@Wilfred007
Wilfred007 merged commit 18e9555 into Protocol-Guild:main Mar 7, 2026
1 check passed
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.

#004: Set Up Horizon Client and Network Configuration

2 participants