zcash-android-wallet-sdk/docs/-synchronizer/index.md

10 KiB

zcash-android-wallet-sdk / cash.z.ecc.android.sdk / Synchronizer

Synchronizer

interface Synchronizer

Primary interface for interacting with the SDK. Defines the contract that specific implementations like MockSynchronizer and SdkSynchronizer fulfill. Given the language-level support for coroutines, we favor their use in the SDK and incorporate that choice into this contract.

Types

Name Summary
Status Represents the status of this Synchronizer, which is useful for communicating to the user.enum class Status

Properties

Name Summary
balances A stream of balance values, separately reflecting both the available and total balance.abstract val balances: Flow<WalletBalance>
clearedTransactions A flow of all the transactions that are on the blockchain.abstract val clearedTransactions: Flow<PagedList<ConfirmedTransaction>>
latestBalance An in-memory reference to the most recently calculated balance.abstract val latestBalance: WalletBalance
latestHeight An in-memory reference to the latest height seen on the network.abstract val latestHeight: Int
onChainErrorHandler A callback to invoke whenever a chain error is encountered. These occur whenever the processor detects a missing or non-chain-sequential block (i.e. a reorg).abstract var onChainErrorHandler: ((Int, Int) -> Any)?
onCriticalErrorHandler Gets or sets a global error handler. This is a useful hook for handling unexpected critical errors.abstract var onCriticalErrorHandler: ((Throwable?) -> Boolean)?
onProcessorErrorHandler An error handler for exceptions during processing. For instance, a block might be missing or a reorg may get mishandled or the database may get corrupted.abstract var onProcessorErrorHandler: ((Throwable?) -> Boolean)?
onSubmissionErrorHandler An error handler for exceptions while submitting transactions to lightwalletd. For instance, a transaction may get rejected because it would be a double-spend or the user might lose their cellphone signal.abstract var onSubmissionErrorHandler: ((Throwable?) -> Boolean)?
pendingTransactions A flow of all the outbound pending transaction that have been sent but are awaiting confirmations.abstract val pendingTransactions: Flow<List<PendingTransaction>>
processorInfo A flow of processor details, updated every time blocks are processed to include the latest block height, blocks downloaded and blocks scanned. Similar to the progress flow but with a lot more detail.abstract val processorInfo: Flow<ProcessorInfo>
progress A flow of progress values, typically corresponding to this Synchronizer downloading blocks. Typically, any non- zero value below 100 indicates that progress indicators can be shown and a value of 100 signals that progress is complete and any progress indicators can be hidden.abstract val progress: Flow<Int>
receivedTransactions A flow of all transactions related to receiving funds.abstract val receivedTransactions: Flow<PagedList<ConfirmedTransaction>>
sentTransactions A flow of all transactions related to sending funds.abstract val sentTransactions: Flow<PagedList<ConfirmedTransaction>>
status A flow of values representing the Status of this Synchronizer. As the status changes, a new value will be emitted by this flow.abstract val status: Flow<Status>

Functions

Name Summary
cancelSpend Attempts to cancel a transaction that is about to be sent. Typically, cancellation is only an option if the transaction has not yet been submitted to the server.abstract suspend fun cancelSpend(transaction: PendingTransaction): Boolean
getAddress Gets the address for the given account.abstract suspend fun getAddress(accountId: Int= 0):String
getServerInfo Convenience function that exposes the underlying server information, like its name and consensus branch id. Most wallets should already have a different source of truth for the server(s) with which they operate and thereby not need this function.abstract suspend fun getServerInfo(): <ERROR CLASS>
isValidShieldedAddr Returns true when the given address is a valid z-addr. Invalid addresses will throw an exception. Valid z-addresses have these characteristics: //TODO copy info from related ZIPabstract suspend fun isValidShieldedAddr(address: String): Boolean
isValidTransparentAddr Returns true when the given address is a valid t-addr. Invalid addresses will throw an exception. Valid t-addresses have these characteristics: //TODO copy info from related ZIPabstract suspend fun isValidTransparentAddr(address: String): Boolean
sendToAddress Sends zatoshi.abstract fun sendToAddress(spendingKey: String, zatoshi: Long, toAddress: String, memo: String= "", fromAccountIndex:Int = 0): Flow<PendingTransaction>
start Starts this synchronizer within the given scope.abstract fun start(parentScope: CoroutineScope? = null): Synchronizer
stop Stop this synchronizer. Implementations should ensure that calling this method cancels all jobs that were created by this instance.abstract fun stop(): Unit
validateAddress Validates the given address, returning information about why it is invalid. This is a convenience method that combines the behavior of isValidShieldedAddr and isValidTransparentAddr into one call so that the developer doesn't have to worry about handling the exceptions that they throw. Rather, exceptions are converted to AddressType.Invalid which has a reason property describing why it is invalid.abstract suspend fun validateAddress(address: String): AddressType
validateConsensusBranch Validate whether the server and this SDK share the same consensus branch. This is particularly important to check around network updates so that any wallet that's connected to an incompatible server can surface that information effectively. For the SDK, the consensus branch is used when creating transactions as each one needs to target a specific branch. This function compares the server's branch id to this SDK's and returns information that helps determine whether they match.abstract suspend fun validateConsensusBranch(): ConsensusMatchType

Inheritors

Name Summary
SdkSynchronizer A Synchronizer that attempts to remain operational, despite any number of errors that can occur. It acts as the glue that ties all the pieces of the SDK together. Each component of the SDK is designed for the potential of stand-alone usage but coordinating all the interactions is non- trivial. So the Synchronizer facilitates this, acting as reference that demonstrates how all the pieces can be tied together. Its goal is to allow a developer to focus on their app rather than the nuances of how Zcash works.class SdkSynchronizer : Synchronizer