2019-01-02 21:31:12 -08:00
|
|
|
package cash.z.wallet.sdk.data
|
|
|
|
|
2019-02-14 13:43:06 -08:00
|
|
|
import cash.z.wallet.sdk.dao.WalletTransaction
|
|
|
|
import kotlinx.coroutines.CoroutineScope
|
2019-01-02 21:31:12 -08:00
|
|
|
import kotlinx.coroutines.channels.ReceiveChannel
|
|
|
|
|
2019-02-14 13:43:06 -08:00
|
|
|
interface Synchronizer {
|
2019-01-02 21:31:12 -08:00
|
|
|
|
2019-02-14 13:43:06 -08:00
|
|
|
/* Lifecycle */
|
|
|
|
fun start(parentScope: CoroutineScope): Synchronizer
|
|
|
|
fun stop()
|
2019-01-23 02:45:26 -08:00
|
|
|
|
2019-02-14 13:43:06 -08:00
|
|
|
/* Channels */
|
|
|
|
// NOTE: each of these are expected to be a broadcast channel, such that [receive] always returns the latest value
|
|
|
|
fun activeTransactions(): ReceiveChannel<Map<ActiveTransaction, TransactionState>>
|
|
|
|
fun allTransactions(): ReceiveChannel<List<WalletTransaction>>
|
|
|
|
fun balance(): ReceiveChannel<Long>
|
|
|
|
fun progress(): ReceiveChannel<Int>
|
2019-01-23 02:45:26 -08:00
|
|
|
|
2019-02-14 13:43:06 -08:00
|
|
|
/* Status */
|
|
|
|
suspend fun isOutOfSync(): Boolean
|
|
|
|
suspend fun isFirstRun(): Boolean
|
2019-02-24 15:59:07 -08:00
|
|
|
val address: String
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called whenever there is an uncaught exception.
|
|
|
|
*
|
|
|
|
* @return true when the error has been handled and the Synchronizer should continue. False when the error is
|
|
|
|
* unrecoverable and the Synchronizer should [stop].
|
|
|
|
*/
|
|
|
|
var onSynchronizerErrorListener: ((Throwable?) -> Boolean)?
|
2019-01-23 02:45:26 -08:00
|
|
|
|
2019-02-14 13:43:06 -08:00
|
|
|
/* Operations */
|
|
|
|
suspend fun sendToAddress(zatoshi: Long, toAddress: String)
|
|
|
|
fun cancelSend(transaction: ActiveSendTransaction): Boolean
|
2019-01-02 21:31:12 -08:00
|
|
|
}
|