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)
}
}
}Content copied to clipboard
Constructors
Link copied to clipboard
constructor(context: Context, indexerClient: IndexerClient, utxoManager: UtxoManager, syncStateManager: SyncStateManager)