switchSyncServer method

  1. @override
Future<WalletSession> switchSyncServer(
  1. SyncServerChoice choice
)
override

Switch the active wallet onto choice and REMEMBER it (the picker, P3-13 — sync-server-picker.md D3): the SDK probes the server, stops and joins the sync loop, writes the choice, and rebuilds the session over the SAME database — no rescan, no re-download; funds, history, queued sends and the sync verdict are untouched. Returns a FRESH session over the same handle, the rescanFrom shape, so the live-sync graph (keyed on session identity) rebuilds and re-subscribes; sync auto-restarts on the new server.

A refusal BEFORE the swap (syncServerUnreachable, networkMismatch, syncServerNotOffered, invalidEndpoint, a walletBusy in any phase but switchingServer) leaves the handle OPEN and everything as it was — the typed WalletApiError propagates and the caller keeps its session. A fault PAST the stop-join leaves the handle CLOSED (the rescanFrom contract): the OnboardingController owns the recover-by-reopen. Valid only after a createGenerated/open/restore on this instance.

Implementation

@override
Future<WalletSession> switchSyncServer(SyncServerChoice choice) async {
  switchCount++;
  lastSwitchChoice = choice;
  if (holdSwitch != null) await holdSwitch!.future;
  if (failSwitch != null) throw failSwitch!;
  return switchSession ?? FakeWalletSession();
}