-
public final class CompactBlockProcessorResponsible for processing the compact blocks that are received from the lightwallet server. This class encapsulates all the business logic required to validate and scan the blockchain and is therefore tightly coupled with librustzcash.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classCompactBlockProcessor.BlockProcessingResultpublic classCompactBlockProcessor.Companionpublic classCompactBlockProcessor.StateSealed class representing the various states of this processor.
public final classCompactBlockProcessor.ProcessorInfoData class for holding detailed information about the processor.
public final classCompactBlockProcessor.ValidationErrorInfo
-
Field Summary
Fields Modifier and Type Field Description private Function1<Throwable, Boolean>onProcessorErrorListenerprivate Function2<BlockHeight, BlockHeight, Object>onChainErrorListenerprivate Function1<Throwable, Boolean>onSetupErrorListenerprivate final ZcashNetworknetworkprivate final <ERROR CLASS>stateprivate final <ERROR CLASS>progressprivate final <ERROR CLASS>processorInfoprivate final <ERROR CLASS>networkHeightprivate final <ERROR CLASS>birthdayHeightprivate final <ERROR CLASS>fullyScannedHeightprivate final CompactBlockDownloaderdownloader
-
Method Summary
Modifier and Type Method Description final Function1<Throwable, Boolean>getOnProcessorErrorListener()Callback for any non-trivial errors that occur while processing compact blocks. final UnitsetOnProcessorErrorListener(Function1<Throwable, Boolean> onProcessorErrorListener)Callback for any non-trivial errors that occur while processing compact blocks. final Function2<BlockHeight, BlockHeight, Object>getOnChainErrorListener()Callback for reorgs. final UnitsetOnChainErrorListener(Function2<BlockHeight, BlockHeight, Object> onChainErrorListener)Callback for reorgs. final Function1<Throwable, Boolean>getOnSetupErrorListener()Callback for setup errors that occur prior to processing compact blocks. final UnitsetOnSetupErrorListener(Function1<Throwable, Boolean> onSetupErrorListener)Callback for setup errors that occur prior to processing compact blocks. final ZcashNetworkgetNetwork()The zcash network that is being processed. final <ERROR CLASS>getState()The flow of state values so that a wallet can monitor the state of this class without needing to poll. final <ERROR CLASS>getProgress()The flow of progress values so that a wallet can monitor how much downloading remains without needing to poll. final <ERROR CLASS>getProcessorInfo()The flow of detailed processorInfo like the range of blocks that shall be downloaded and scanned. final <ERROR CLASS>getNetworkHeight()The flow of network height. final <ERROR CLASS>getBirthdayHeight()The first block this wallet cares about anything prior can be ignored. final <ERROR CLASS>getFullyScannedHeight()The flow of fully scanned height. final CompactBlockDownloadergetDownloader()final Unitstart()Download compact blocks, verify and scan them until stop is called. final BooleancheckErrorAndFail(BlockHeight failedHeight, Throwable failCause)Checks the block synchronization retry attempts and fails with throwing the failCause error once RETRIES count is reached. final Unitstop()Sets the state to State.Stopped, which causes the processor loop to exit. final BlockHeightgetNearestRewindHeight(BlockHeight height)final BooleanquickRewind()Rewind back two weeks worth of blocks. final BooleanrewindToNearestHeight(BlockHeight height)final BlockHeightcalculateBirthdayHeight()final ZatoshigetUtxoCacheBalance(String address)-
-
Method Detail
-
getOnProcessorErrorListener
final Function1<Throwable, Boolean> getOnProcessorErrorListener()
Callback for any non-trivial errors that occur while processing compact blocks.
-
setOnProcessorErrorListener
final Unit setOnProcessorErrorListener(Function1<Throwable, Boolean> onProcessorErrorListener)
Callback for any non-trivial errors that occur while processing compact blocks.
-
getOnChainErrorListener
final Function2<BlockHeight, BlockHeight, Object> getOnChainErrorListener()
Callback for reorgs. This callback is invoked when validation fails with the height at which an error was found and the lower bound to which the data will rewind, at most.
-
setOnChainErrorListener
final Unit setOnChainErrorListener(Function2<BlockHeight, BlockHeight, Object> onChainErrorListener)
Callback for reorgs. This callback is invoked when validation fails with the height at which an error was found and the lower bound to which the data will rewind, at most.
-
getOnSetupErrorListener
final Function1<Throwable, Boolean> getOnSetupErrorListener()
Callback for setup errors that occur prior to processing compact blocks. Can be used to override any errors from verifySetup. When this listener is missing then all setup errors will result in the processor 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.
-
setOnSetupErrorListener
final Unit setOnSetupErrorListener(Function1<Throwable, Boolean> onSetupErrorListener)
Callback for setup errors that occur prior to processing compact blocks. Can be used to override any errors from verifySetup. When this listener is missing then all setup errors will result in the processor 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.
-
getNetwork
final ZcashNetwork getNetwork()
The zcash network that is being processed. Either Testnet or Mainnet.
-
getState
final <ERROR CLASS> getState()
The flow of state values so that a wallet can monitor the state of this class without needing to poll.
-
getProgress
final <ERROR CLASS> getProgress()
The flow of progress values so that a wallet can monitor how much downloading remains without needing to poll.
-
getProcessorInfo
final <ERROR CLASS> getProcessorInfo()
The flow of detailed processorInfo like the range of blocks that shall be downloaded and scanned. This gives the wallet a lot of insight into the work of this processor.
-
getNetworkHeight
final <ERROR CLASS> getNetworkHeight()
The flow of network height. This value is updated at the same time that processorInfo is updated but this allows consumers to have the information pushed instead of polling.
-
getBirthdayHeight
final <ERROR CLASS> getBirthdayHeight()
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, rounded down to the nearest 100. So in some cases, this is a dynamic value.
-
getFullyScannedHeight
final <ERROR CLASS> getFullyScannedHeight()
The flow of fully scanned height. This value is updated at the same time as the other values from WalletSummary. fullyScannedHeight is the height below which all blocks have been scanned by the wallet, ignoring blocks below the wallet birthday. This allows consumers to have the information pushed instead of polling.
We can consider moving this property to public API by creating equivalent property on
Synchronizer
-
getDownloader
final CompactBlockDownloader getDownloader()
-
checkErrorAndFail
final Boolean checkErrorAndFail(BlockHeight failedHeight, Throwable failCause)
Checks the block synchronization retry attempts and fails with throwing the failCause error once RETRIES count is reached.
- Parameters:
failedHeight- The height at which the block processing failedfailCause- The cause of the failure to be part of thrown exception
-
stop
final Unit stop()
Sets the state to State.Stopped, which causes the processor loop to exit.
-
getNearestRewindHeight
final BlockHeight getNearestRewindHeight(BlockHeight height)
-
quickRewind
final Boolean quickRewind()
Rewind back two weeks worth of blocks. The final amount of rewinded blocks depends on rewindToNearestHeight.
-
rewindToNearestHeight
final Boolean rewindToNearestHeight(BlockHeight height)
-
calculateBirthdayHeight
final BlockHeight calculateBirthdayHeight()
-
getUtxoCacheBalance
final Zatoshi getUtxoCacheBalance(String address)
-
-
-
-