ZcashLightClientKit/Sources/ZcashLightClientKit/Block/Processor/FigureNextBatchOperation.swift

59 lines
1.5 KiB
Swift
Raw Normal View History

2021-06-17 16:58:30 -07:00
//
// FigureNextBatchOperation.swift
// ZcashLightClientKit
//
// Created by Francisco Gindre on 6/17/21.
//
import Foundation
class FigureNextBatchOperation: ZcashOperation {
enum NextState {
case finishProcessing(height: BlockHeight)
case processNewBlocks(range: CompactBlockRange)
case wait(latestHeight: BlockHeight, latestDownloadHeight: BlockHeight)
}
2021-09-17 06:49:58 -07:00
2021-06-17 16:58:30 -07:00
private var service: LightWalletService
private var downloader: CompactBlockDownloading
private var config: CompactBlockProcessor.Configuration
private var rustBackend: ZcashRustBackendWelding.Type
private(set) var result: NextState?
2021-09-17 06:49:58 -07:00
required init(
downloader: CompactBlockDownloading,
service: LightWalletService,
config: CompactBlockProcessor.Configuration,
rustBackend: ZcashRustBackendWelding.Type
) {
2021-06-17 16:58:30 -07:00
self.service = service
self.config = config
self.downloader = downloader
self.rustBackend = rustBackend
2021-09-17 06:49:58 -07:00
2021-06-17 16:58:30 -07:00
super.init()
2021-09-17 06:49:58 -07:00
2021-06-17 16:58:30 -07:00
self.name = "Next Batch Operation"
}
override func main() {
guard !shouldCancel() else {
cancel()
return
}
2021-09-17 06:49:58 -07:00
2021-06-17 16:58:30 -07:00
self.startedHandler?()
do {
2021-09-17 06:49:58 -07:00
result = try CompactBlockProcessor.NextStateHelper.nextState(
service: self.service,
downloader: self.downloader,
config: self.config,
rustBackend: self.rustBackend
)
2021-06-17 16:58:30 -07:00
} catch {
self.fail(error: error)
}
}
}