SubscriptionManager

class SubscriptionManager(context: Context, indexerClient: IndexerClient, utxoManager: UtxoManager, syncStateManager: SyncStateManager)

Manages subscription lifecycle for UTXO syncing.

This is the missing piece that connects everything:

  • Starts subscription via IndexerClient

  • Collects updates from subscription Flow

  • Passes updates to UtxoManager for processing

  • Persists sync progress via SyncStateManager

  • Handles reconnection with exponential backoff

Why this was missing: All the pieces existed (IndexerClient, UtxoManager, WebSocket client), but nothing ever called subscribeToUnshieldedTransactions() and collected from it. This class fixes that critical gap.

Usage:

// In ViewModel or background service
val subscriptionManager = SubscriptionManager(indexerClient, utxoManager, syncStateManager)

// Start syncing (will resume from last processed transaction)
viewModelScope.launch {
subscriptionManager.startSubscription(address)
.collect { state ->
when (state) {
is SyncState.Syncing -> updateUI("Syncing: ${state.processedCount} txs")
is SyncState.Synced -> updateUI("Synced up to block ${state.blockHeight}")
is SyncState.Error -> showError(state.message)
}
}
}

Constructors

Link copied to clipboard
constructor(context: Context, indexerClient: IndexerClient, utxoManager: UtxoManager, syncStateManager: SyncStateManager)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun startSubscription(address: String, forceFullResync: Boolean = false): Flow<SyncState>

Start subscription for an address with automatic reconnection.