-
public interface Synchronizer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumSynchronizer.StatusRepresents the status of this Synchronizer, which is useful for communicating to the user.
public classSynchronizer.Companion
-
Method Summary
Modifier and Type Method Description abstract Flow<FastestServersResult>getFastestServers(Context context, List<LightWalletEndpoint> servers)Measure connection quality and speed of given servers. abstract StringgetUnifiedAddress(Account account)Adds the next available account-level spend authority, given the current set of ZIP 316 account identifiers known, to the wallet database. abstract StringgetSaplingAddress(Account account)Gets the legacy Sapling address corresponding to the current unified address for the given account. abstract StringgetTransparentAddress(Account account)Gets the legacy transparent address corresponding to the current unified address for the given account. abstract UnitrefreshExchangeRateUsd()Refreshes exchangeRateUsd. abstract ProposalproposeTransfer(Account account, String recipient, Zatoshi amount, String memo)Creates a proposal for transferring funds to the given recipient. abstract ProposalproposeShielding(Account account, Zatoshi shieldingThreshold, String memo, String transparentReceiver)Creates a proposal for shielding any transparent funds received by the given account. abstract Flow<TransactionSubmitResult>createProposedTransactions(Proposal proposal, UnifiedSpendingKey usk)Creates the transactions in the given proposal. abstract LongsendToAddress(UnifiedSpendingKey usk, Zatoshi amount, String toAddress, String memo)Sends zatoshi. abstract LongshieldFunds(UnifiedSpendingKey usk, String memo)abstract BooleanisValidShieldedAddr(String address)Returns true when the given address is a valid z-addr. abstract BooleanisValidTransparentAddr(String address)Returns true when the given address is a valid t-addr. abstract BooleanisValidUnifiedAddr(String address)Returns true when the given address is a valid ZIP 316 unified address. abstract BooleanisValidTexAddr(String address)Returns true when the given address is a valid ZIP 320 TEX address. abstract ConsensusMatchTypevalidateConsensusBranch()Validate whether the server and this SDK share the same consensus branch. abstract ServerValidationvalidateServerEndpoint(Context context, LightWalletEndpoint endpoint)This function checks whether the provided server endpoint is valid. abstract AddressTypevalidateAddress(String address)Validates the given address, returning information about why it is invalid. abstract IntegerrefreshUtxos(Account account, BlockHeight since)Download all UTXOs for the given account addresses and store any new ones in the database. abstract ZatoshigetTransparentBalance(String tAddr)Returns the balance that the wallet knows about. abstract BlockHeightgetNearestRewindHeight(BlockHeight height)Returns the safest height to which we can rewind, given a desire to rewind to the height provided. abstract UnitrewindToNearestHeight(BlockHeight height)Rewinds to the safest height to which we can rewind, given a desire to rewind to the height provided. abstract UnitquickRewind()Rewinds to the safest height approximately 14 days backward from the current chain tip. abstract Flow<String>getMemos(TransactionOverview transactionOverview)Returns a stream of memos for a transaction. abstract Flow<TransactionRecipient>getRecipients(TransactionOverview transactionOverview)Returns a list of recipients for a transaction. abstract StringgetExistingDataDbFilePath(Context context, ZcashNetwork network, String alias)Checks and provides file path to the existing data database file for the given input parameters or throws InitializeException.MissingDatabaseException if the database does not exist yet. abstract ZcashNetworkgetNetwork()The network to which this synchronizer is connected and from which it is processing blocks. abstract Flow<Synchronizer.Status>getStatus()A flow of values representing the Status of this Synchronizer. abstract Flow<PercentDecimal>getProgress()A flow of progress values, typically corresponding to this Synchronizer downloading blocks. abstract Flow<CompactBlockProcessor.ProcessorInfo>getProcessorInfo()A flow of processor details, updated every time blocks are processed to include the latest block height, blocks downloaded and blocks scanned. abstract StateFlow<BlockHeight>getNetworkHeight()The latest height observed on the network, which does not necessarily correspond to the latest downloaded height or scanned height. abstract StateFlow<WalletBalance>getOrchardBalances()A stream of balance values for the orchard pool. abstract StateFlow<WalletBalance>getSaplingBalances()A stream of balance values for the sapling pool. abstract StateFlow<Zatoshi>getTransparentBalance()A stream of a balance for the transparent pool. abstract StateFlow<ObserveFiatCurrencyResult>getExchangeRateUsd()The latest known USD/ZEC exchange rate, paired with the time it was queried. abstract Flow<List<TransactionOverview>>getTransactions()A flow of all the transactions that are on the blockchain. abstract BlockHeightgetLatestHeight()An in-memory reference to the latest height seen on the network. abstract BlockHeightgetLatestBirthdayHeight()An in-memory reference to the best known birthday height, which can change if the first transaction has not yet occurred. abstract Function1<Throwable, Boolean>getOnCriticalErrorHandler()Gets or sets a global error handler. abstract UnitsetOnCriticalErrorHandler(Function1<Throwable, Boolean> onCriticalErrorHandler)Gets or sets a global error handler. abstract Function1<Throwable, Boolean>getOnProcessorErrorHandler()An error handler for exceptions during processing. abstract UnitsetOnProcessorErrorHandler(Function1<Throwable, Boolean> onProcessorErrorHandler)An error handler for exceptions during processing. abstract Function1<Throwable, Boolean>getOnSubmissionErrorHandler()An error handler for exceptions while submitting transactions to lightwalletd. abstract UnitsetOnSubmissionErrorHandler(Function1<Throwable, Boolean> onSubmissionErrorHandler)An error handler for exceptions while submitting transactions to lightwalletd. abstract Function1<Throwable, Boolean>getOnSetupErrorHandler()Callback for setup errors that occur prior to processing compact blocks. abstract UnitsetOnSetupErrorHandler(Function1<Throwable, Boolean> onSetupErrorHandler)Callback for setup errors that occur prior to processing compact blocks. abstract Function2<BlockHeight, BlockHeight, Object>getOnChainErrorHandler()A callback to invoke whenever a chain error is encountered. abstract UnitsetOnChainErrorHandler(Function2<BlockHeight, BlockHeight, Object> onChainErrorHandler)A callback to invoke whenever a chain error is encountered. -
-
Method Detail
-
getFastestServers
abstract Flow<FastestServersResult> getFastestServers(Context context, List<LightWalletEndpoint> servers)
Measure connection quality and speed of given servers.
-
getUnifiedAddress
abstract String getUnifiedAddress(Account account)
Adds the next available account-level spend authority, given the current set of ZIP 316 account identifiers known, to the wallet database.
The caller should store the byte encoding of the returned spending key in a secure fashion. This encoding MUST NOT be exposed to users. It is an internal encoding that is inherently unstable, and only intended to be passed between the SDK and the storage backend. The caller MUST NOT allow this encoding to be exported or imported.
If
seedwas imported from a backup and this method is being used to restore a previous wallet state, you should use this method to add all of the desired accounts before scanning the chain from the seed's birthday height.By convention, wallets should only allow a new account to be generated after funds have been received by the currently-available account (in order to enable automated account recovery).
-
getSaplingAddress
abstract String getSaplingAddress(Account account)
Gets the legacy Sapling address corresponding to the current unified address for the given account.
- Parameters:
account- the account whose address is of interest.
-
getTransparentAddress
abstract String getTransparentAddress(Account account)
Gets the legacy transparent address corresponding to the current unified address for the given account.
- Parameters:
account- the account whose address is of interest.
-
refreshExchangeRateUsd
abstract Unit refreshExchangeRateUsd()
Refreshes exchangeRateUsd.
-
proposeTransfer
abstract Proposal proposeTransfer(Account account, String recipient, Zatoshi amount, String memo)
Creates a proposal for transferring funds to the given recipient.
- Parameters:
account- the account from which to transfer funds.recipient- the recipient's address.amount- the amount of zatoshi to send.memo- the optional memo to include as part of the proposal's transactions.
-
proposeShielding
abstract Proposal proposeShielding(Account account, Zatoshi shieldingThreshold, String memo, String transparentReceiver)
Creates a proposal for shielding any transparent funds received by the given account.
- Parameters:
account- the account for which to shield funds.shieldingThreshold- the minimum transparent balance required before a proposal will be created.memo- the optional memo to include as part of the proposal's transactions.transparentReceiver- a specific transparent receiver within the account that should be the source of transparent funds.
-
createProposedTransactions
abstract Flow<TransactionSubmitResult> createProposedTransactions(Proposal proposal, UnifiedSpendingKey usk)
Creates the transactions in the given proposal.
- Parameters:
proposal- the proposal for which to create transactions.usk- the unified spending key associated with the account for which the proposal was created.
-
sendToAddress
@Deprecated(message = Upcoming SDK 2.1 will create multiple transactions at once for some recipients., replaceWith = @ReplaceWith(imports = {}, expression = createProposedTransactions(proposeTransfer(usk.account, toAddress, amount, memo), usk))) abstract Long sendToAddress(UnifiedSpendingKey usk, Zatoshi amount, String toAddress, String memo)
Sends zatoshi.
- Parameters:
usk- the unified spending key associated with the notes that will be spent.amount- the amount of zatoshi to send.toAddress- the recipient's address.memo- the optional memo to include as part of the transaction.
-
shieldFunds
@Deprecated(message = Upcoming SDK 2.1 will create multiple transactions at once for some recipients., replaceWith = @ReplaceWith(imports = {}, expression = proposeShielding(usk.account, shieldingThreshold, memo)?.let { createProposedTransactions(it, usk) })) abstract Long shieldFunds(UnifiedSpendingKey usk, String memo)
-
isValidShieldedAddr
abstract Boolean isValidShieldedAddr(String address)
Returns true when the given address is a valid z-addr. Invalid addresses will throw an exception. See valid z-addresses characteristics in related ZIP.
- Parameters:
address- the address to validate.
-
isValidTransparentAddr
abstract Boolean isValidTransparentAddr(String address)
Returns true when the given address is a valid t-addr. Invalid addresses will throw an exception. See valid t-addresses characteristics in related ZIP.
- Parameters:
address- the address to validate.
-
isValidUnifiedAddr
abstract Boolean isValidUnifiedAddr(String address)
Returns true when the given address is a valid ZIP 316 unified address.
This method is intended for type checking (e.g. form validation). Invalid addresses will throw an exception.
- Parameters:
address- the address to validate.
-
isValidTexAddr
abstract Boolean isValidTexAddr(String address)
Returns true when the given address is a valid ZIP 320 TEX address.
This method is intended for type checking (e.g. form validation). Invalid addresses will throw an exception. See valid t-addresses characteristics in the related ZIP.
- Parameters:
address- the address to validate.
-
validateConsensusBranch
abstract ConsensusMatchType 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.
-
validateServerEndpoint
abstract ServerValidation validateServerEndpoint(Context context, LightWalletEndpoint endpoint)
This function checks whether the provided server endpoint is valid. The validation is based on comparing:
network types,
sapling activation heights
consensus branches
- Parameters:
context- Contextendpoint- LightWalletEndpoint data to be validated
-
validateAddress
abstract AddressType validateAddress(String address)
Validates the given address, returning information about why it is invalid. This is a convenience method that combines the behavior of isValidShieldedAddr, isValidTransparentAddr, and isValidUnifiedAddr 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
reasonproperty describing why it is invalid.- Parameters:
address- the address to validate.
-
refreshUtxos
abstract Integer refreshUtxos(Account account, BlockHeight since)
Download all UTXOs for the given account addresses and store any new ones in the database.
- Parameters:
account- The Account, for which all addresses blocks will be downloaded.since- The BlockHeight, from which blocks will be downloaded.
-
getTransparentBalance
abstract Zatoshi getTransparentBalance(String tAddr)
Returns the balance that the wallet knows about. This should be called after refreshUtxos.
-
getNearestRewindHeight
abstract BlockHeight getNearestRewindHeight(BlockHeight height)
Returns the safest height to which we can rewind, given a desire to rewind to the height provided. Due to how witness incrementing works, a wallet cannot simply rewind to any arbitrary height. This handles all that complexity yet remains flexible in the future as improvements are made.
-
rewindToNearestHeight
abstract Unit rewindToNearestHeight(BlockHeight height)
Rewinds to the safest height to which we can rewind, given a desire to rewind to the height provided. Due to how witness incrementing works, a wallet cannot simply rewind to any arbitrary height. This handles all that complexity yet remains flexible in the future as improvements are made.
-
quickRewind
abstract Unit quickRewind()
Rewinds to the safest height approximately 14 days backward from the current chain tip. Due to how witness incrementing works, a wallet cannot simply rewind to any arbitrary height. This handles all that complexity yet remains flexible in the future as improvements are made.
-
getMemos
abstract Flow<String> getMemos(TransactionOverview transactionOverview)
Returns a stream of memos for a transaction. It works for both received and sent transaction.
Note that this function internally resolves any error which comes, logs it, and then transforms it to an empty string.
- Parameters:
transactionOverview- For which the memos will be queried
-
getRecipients
abstract Flow<TransactionRecipient> getRecipients(TransactionOverview transactionOverview)
Returns a list of recipients for a transaction.
-
getExistingDataDbFilePath
abstract String getExistingDataDbFilePath(Context context, ZcashNetwork network, String alias)
Checks and provides file path to the existing data database file for the given input parameters or throws InitializeException.MissingDatabaseException if the database does not exist yet.
Note that it's the caller's responsibility to provide a network and alias to an existing database. Otherwise InitializeException.MissingDatabaseException is thrown.
-
getNetwork
abstract ZcashNetwork getNetwork()
The network to which this synchronizer is connected and from which it is processing blocks.
-
getStatus
abstract Flow<Synchronizer.Status> getStatus()
A flow of values representing the Status of this Synchronizer. As the status changes, a new value will be emitted by this flow.
-
getProgress
abstract Flow<PercentDecimal> getProgress()
A flow of progress values, typically corresponding to this Synchronizer downloading blocks. Typically, any non-zero value below
PercentDecimal.ONE_HUNDRED_PERCENTindicates that progress indicators can be shown and a value ofPercentDecimal.ONE_HUNDRED_PERCENTsignals that progress is complete and any progress indicators can be hidden.
-
getProcessorInfo
abstract Flow<CompactBlockProcessor.ProcessorInfo> getProcessorInfo()
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.
-
getNetworkHeight
abstract StateFlow<BlockHeight> getNetworkHeight()
The latest height observed on the network, which does not necessarily correspond to the latest downloaded height or scanned height. Although this is present in processorInfo, it is such a frequently used value that it is convenient to have the real-time value by itself.
-
getOrchardBalances
abstract StateFlow<WalletBalance> getOrchardBalances()
A stream of balance values for the orchard pool.
-
getSaplingBalances
abstract StateFlow<WalletBalance> getSaplingBalances()
A stream of balance values for the sapling pool.
-
getTransparentBalance
abstract StateFlow<Zatoshi> getTransparentBalance()
A stream of a balance for the transparent pool.
-
getExchangeRateUsd
abstract StateFlow<ObserveFiatCurrencyResult> getExchangeRateUsd()
The latest known USD/ZEC exchange rate, paired with the time it was queried.
The rate can be initialized and refreshed by calling refreshExchangeRateUsd.
-
getTransactions
abstract Flow<List<TransactionOverview>> getTransactions()
A flow of all the transactions that are on the blockchain.
-
getLatestHeight
abstract BlockHeight getLatestHeight()
An in-memory reference to the latest height seen on the network.
-
getLatestBirthdayHeight
abstract BlockHeight getLatestBirthdayHeight()
An in-memory reference to the best known birthday height, which can change if the first transaction has not yet occurred.
-
getOnCriticalErrorHandler
abstract Function1<Throwable, Boolean> getOnCriticalErrorHandler()
Gets or sets a global error handler. This is a useful hook for handling unexpected critical errors.
-
setOnCriticalErrorHandler
abstract Unit setOnCriticalErrorHandler(Function1<Throwable, Boolean> onCriticalErrorHandler)
Gets or sets a global error handler. This is a useful hook for handling unexpected critical errors.
-
getOnProcessorErrorHandler
abstract Function1<Throwable, Boolean> getOnProcessorErrorHandler()
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.
-
setOnProcessorErrorHandler
abstract Unit setOnProcessorErrorHandler(Function1<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.
-
getOnSubmissionErrorHandler
abstract Function1<Throwable, Boolean> getOnSubmissionErrorHandler()
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.
-
setOnSubmissionErrorHandler
abstract Unit setOnSubmissionErrorHandler(Function1<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.
-
getOnSetupErrorHandler
abstract Function1<Throwable, Boolean> getOnSetupErrorHandler()
Callback for setup errors that occur prior to processing compact blocks. Can be used to override any errors encountered during setup. When this listener is missing then all setup errors will result in the synchronizer not starting. This is particularly useful for wallets to receive a callback right before the SDK will reject a lightwalletd server because it appears not to match.
-
setOnSetupErrorHandler
abstract Unit setOnSetupErrorHandler(Function1<Throwable, Boolean> onSetupErrorHandler)
Callback for setup errors that occur prior to processing compact blocks. Can be used to override any errors encountered during setup. When this listener is missing then all setup errors will result in the synchronizer not starting. This is particularly useful for wallets to receive a callback right before the SDK will reject a lightwalletd server because it appears not to match.
-
getOnChainErrorHandler
abstract Function2<BlockHeight, BlockHeight, Object> getOnChainErrorHandler()
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). At a minimum, it is best to log these errors because they are the most common source of bugs and unexpected behavior in wallets, due to the chain data mutating and wallets becoming out of sync.
-
setOnChainErrorHandler
abstract Unit setOnChainErrorHandler(Function2<BlockHeight, BlockHeight, Object> 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). At a minimum, it is best to log these errors because they are the most common source of bugs and unexpected behavior in wallets, due to the chain data mutating and wallets becoming out of sync.
-
-
-
-