Update Synchronizer and Processor APIs to enable changing the server.
Actual implementation is in a subsequent commit.
This commit is contained in:
parent
58925b04b3
commit
24f7433f1c
|
@ -78,7 +78,7 @@ class SdkSynchronizer internal constructor(
|
|||
* the underlying channel to connect to the same service, and use other APIs
|
||||
* (such as darksidewalletd) because channels are heavyweight.
|
||||
*/
|
||||
val channel: ManagedChannel get() = (processor.downloader.lightwalletService as LightWalletGrpcService).channel
|
||||
val channel: ManagedChannel get() = (processor.downloader.lightWalletService as LightWalletGrpcService).channel
|
||||
|
||||
var isStarted = false
|
||||
|
||||
|
@ -223,7 +223,18 @@ class SdkSynchronizer internal constructor(
|
|||
*/
|
||||
override suspend fun getServerInfo(): Service.LightdInfo = processor.downloader.getServerInfo()
|
||||
|
||||
|
||||
/**
|
||||
* Changes the server that is being used to download compact blocks. This will throw an
|
||||
* exception if it detects that the server change is invalid e.g. switching to testnet from
|
||||
* mainnet.
|
||||
*/
|
||||
override suspend fun changeServer(host: String, port: Int, errorHandler: (Throwable) -> Unit) {
|
||||
val info =
|
||||
(processor.downloader.lightWalletService as LightWalletGrpcService).connectionInfo
|
||||
processor.downloader.changeService(LightWalletGrpcService(info.appContext, host, port))
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Storage APIs
|
||||
//
|
||||
|
|
|
@ -5,6 +5,7 @@ import cash.z.ecc.android.sdk.block.CompactBlockProcessor
|
|||
import cash.z.ecc.android.sdk.block.CompactBlockProcessor.WalletBalance
|
||||
import cash.z.ecc.android.sdk.db.entity.ConfirmedTransaction
|
||||
import cash.z.ecc.android.sdk.db.entity.PendingTransaction
|
||||
import cash.z.ecc.android.sdk.ext.ZcashSdk
|
||||
import cash.z.ecc.android.sdk.validate.AddressType
|
||||
import cash.z.ecc.android.sdk.validate.ConsensusMatchType
|
||||
import cash.z.wallet.sdk.rpc.Service
|
||||
|
@ -221,6 +222,18 @@ interface Synchronizer {
|
|||
*/
|
||||
suspend fun getServerInfo(): Service.LightdInfo
|
||||
|
||||
/**
|
||||
* Gracefully change the server that the Synchronizer is currently using. In some cases, this
|
||||
* will require waiting until current network activity is complete. Ideally, this would protect
|
||||
* against accidentally switching between testnet and mainnet, by comparing the service info of
|
||||
* the existing server with that of the new one.
|
||||
*/
|
||||
suspend fun changeServer(
|
||||
host: String,
|
||||
port: Int = ZcashSdk.DEFAULT_LIGHTWALLETD_PORT,
|
||||
errorHandler: (Throwable) -> Unit = { throw it }
|
||||
)
|
||||
|
||||
|
||||
//
|
||||
// Error Handling
|
||||
|
|
|
@ -170,7 +170,7 @@ class CompactBlockProcessor(
|
|||
if (!updateRanges()) {
|
||||
twig("Disconnection detected! Attempting to reconnect!")
|
||||
setState(Disconnected)
|
||||
downloader.lightwalletService.reconnect()
|
||||
downloader.lightWalletService.reconnect()
|
||||
ERROR_CODE_RECONNECT
|
||||
} else if (currentInfo.lastDownloadRange.isEmpty() && currentInfo.lastScanRange.isEmpty()) {
|
||||
twig("Nothing to process: no new blocks to download or scan, right now.")
|
||||
|
|
Loading…
Reference in New Issue