Skip to content

Multi-Network Environment Configuration Switcher #587

Description

@Kingsman-99

Description

The SDK is initialized with hard-coded Horizon and Soroban RPC URLs, making it cumbersome to switch between mainnet, testnet, and futurenet during development or integration testing without re-instantiating the entire client. A first-class environment switcher would provide built-in network presets, validate that the active network passphrase matches the RPC endpoint's reported passphrase, and allow runtime network swapping while in-flight requests finish cleanly.

Technical Context

Extends src/config.ts with a NetworkEnvironment enum (MAINNET | TESTNET | FUTURENET | CUSTOM) and a NetworkPreset interface mapping each value to { horizonUrl: string; rpcUrl: string; networkPassphrase: string }. The StellarSplitClient in src/client.ts gains a switchNetwork(env: NetworkEnvironment | NetworkPreset): Promise<void> method. Passphrase cross-check uses SorobanRpc.Server.getNetwork() from @stellar/stellar-sdk.

Acceptance Criteria

  • switchNetwork(NetworkEnvironment.TESTNET) reconfigures internal Horizon and RPC URL references and validates the passphrase against the live RPC endpoint before accepting the switch
  • Passing NetworkEnvironment.CUSTOM without a full NetworkPreset object produces a TypeScript compile-time error via function overload typing
  • In-flight requests at the moment of a switch complete against the original network; requests issued after switchNetwork resolves use the new configuration
  • A NetworkMismatchError (with expected and actual passphrase fields) is thrown when the live RPC passphrase does not match the preset
  • Tests cover successful switch, passphrase mismatch rejection, and concurrent-request safety during the switchover window
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions