New: Expose network height as a StateFlow.
We already had latest height but that would require polling. Having a state flow makes it easier for views to be pushed the latest height.
This commit is contained in:
parent
095f118fac
commit
0c73f2b585
|
@ -66,6 +66,7 @@ import kotlinx.coroutines.SupervisorJob
|
|||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.channels.ConflatedBroadcastChannel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.first
|
||||
|
@ -170,6 +171,8 @@ class SdkSynchronizer internal constructor(
|
|||
*/
|
||||
override val processorInfo: Flow<CompactBlockProcessor.ProcessorInfo> = processor.processorInfo
|
||||
|
||||
override val networkHeight: StateFlow<Int> = processor.networkHeight
|
||||
|
||||
//
|
||||
// Error Handling
|
||||
//
|
||||
|
|
|
@ -12,6 +12,7 @@ import cash.z.ecc.android.sdk.type.ZcashNetwork
|
|||
import cash.z.wallet.sdk.rpc.Service
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
/**
|
||||
* Primary interface for interacting with the SDK. Defines the contract that specific
|
||||
|
@ -91,6 +92,8 @@ interface Synchronizer {
|
|||
*/
|
||||
val processorInfo: Flow<CompactBlockProcessor.ProcessorInfo>
|
||||
|
||||
val networkHeight: StateFlow<Int>
|
||||
|
||||
/**
|
||||
* A stream of balance values, separately reflecting both the available and total balance.
|
||||
*/
|
||||
|
|
|
@ -47,6 +47,7 @@ import kotlinx.coroutines.channels.ConflatedBroadcastChannel
|
|||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
|
@ -120,6 +121,7 @@ class CompactBlockProcessor(
|
|||
private val _state: ConflatedBroadcastChannel<State> = ConflatedBroadcastChannel(Initialized)
|
||||
private val _progress = ConflatedBroadcastChannel(0)
|
||||
private val _processorInfo = ConflatedBroadcastChannel(ProcessorInfo())
|
||||
private val _networkHeight = MutableStateFlow(-1)
|
||||
private val processingMutex = Mutex()
|
||||
|
||||
/**
|
||||
|
@ -161,6 +163,8 @@ class CompactBlockProcessor(
|
|||
*/
|
||||
val processorInfo = _processorInfo.asFlow()
|
||||
|
||||
val networkHeight = _networkHeight.asStateFlow()
|
||||
|
||||
/**
|
||||
* The first block this wallet cares about anything prior can be ignored. If a wallet has no
|
||||
* transactions, this value will later update to 100 blocks before the first transaction,
|
||||
|
@ -583,6 +587,7 @@ class CompactBlockProcessor(
|
|||
lastScanRange = lastScanRange,
|
||||
lastDownloadRange = lastDownloadRange
|
||||
)
|
||||
_networkHeight.value = networkBlockHeight
|
||||
_processorInfo.send(currentInfo)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue