Merge pull request #615 from zcash/prepare_sync
[#614] make prepare(with:) and get{pool_type}Address() synchronous
This commit is contained in:
commit
4e07a2093f
|
@ -3,7 +3,7 @@ os: osx
|
|||
osx_image: xcode14
|
||||
xcode_project: ./Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj
|
||||
xcode_scheme: ZcashLightClientSample
|
||||
xcode_destination: platform=iOS Simulator,OS=15.5,name=iPhone 8
|
||||
xcode_destination: platform=iOS Simulator,OS=16.0,name=iPhone 14
|
||||
addons:
|
||||
homebrew:
|
||||
packages:
|
||||
|
|
|
@ -86,8 +86,8 @@
|
|||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/zcash-hackworks/zcash-light-client-ffi",
|
||||
"state" : {
|
||||
"revision" : "70bf6ae6538943f2b8453f424e607a05f4dc7be6",
|
||||
"version" : "0.1.0-beta.2"
|
||||
"revision" : "7febbfd74a7d963ec206e01f8ef6090bb8cee523",
|
||||
"version" : "0.1.0-beta.3"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
|
|
@ -560,21 +560,6 @@ public actor CompactBlockProcessor {
|
|||
self.lowerBoundHeight = try? downloader.lastDownloadedBlockHeight()
|
||||
return BlockHeight(rewindHeight)
|
||||
}
|
||||
/**
|
||||
changes the wallet birthday in configuration. Use this method when wallet birthday is not available and the processor can't be lazy initialized.
|
||||
- Note: this does not rewind your chain state
|
||||
- Parameter startHeight: the wallet birthday for this compact block processor
|
||||
- Throws CompactBlockProcessorError.invalidConfiguration if block height is invalid or if processor is already started
|
||||
*/
|
||||
func setStartHeight(_ startHeight: BlockHeight) throws {
|
||||
guard self.state == .stopped, startHeight >= config.network.constants.saplingActivationHeight else {
|
||||
throw CompactBlockProcessorError.invalidConfiguration
|
||||
}
|
||||
|
||||
var config = self.config
|
||||
config.walletBirthday = startHeight
|
||||
self.config = config
|
||||
}
|
||||
|
||||
func validateServer() async {
|
||||
do {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import Foundation
|
||||
|
||||
extension CompactBlockProcessor {
|
||||
enum NextState {
|
||||
enum NextState: Equatable {
|
||||
case finishProcessing(height: BlockHeight)
|
||||
case processNewBlocks(range: CompactBlockRange, latestBlockHeight: BlockHeight)
|
||||
case wait(latestHeight: BlockHeight, latestDownloadHeight: BlockHeight)
|
||||
|
|
|
@ -384,3 +384,15 @@ extension InitializerError: LocalizedError {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Synchronous helpers that support clients that don't use structured concurrency yet
|
||||
extension Initializer {
|
||||
func getCurrentAddress(accountIndex: Int) -> UnifiedAddress? {
|
||||
try? self.rustBackend.getCurrentAddress(
|
||||
dbData: self.dataDbURL,
|
||||
account: Int32(accountIndex),
|
||||
networkType: self.network.networkType
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,12 +156,11 @@ public class SDKSynchronizer: Synchronizer {
|
|||
}
|
||||
}
|
||||
|
||||
public func prepare(with seed: [UInt8]?) async throws -> Initializer.InitializationResult {
|
||||
public func prepare(with seed: [UInt8]?) throws -> Initializer.InitializationResult {
|
||||
if case .seedRequired = try self.initializer.initialize(with: seed) {
|
||||
return .seedRequired
|
||||
}
|
||||
|
||||
try await self.blockProcessor.setStartHeight(initializer.walletBirthday)
|
||||
self.status = .disconnected
|
||||
|
||||
return .success
|
||||
|
@ -624,7 +623,6 @@ public class SDKSynchronizer: Synchronizer {
|
|||
await blockProcessor.getTransparentAddress(accountIndex: accountIndex)
|
||||
}
|
||||
|
||||
|
||||
/// Returns the last stored transparent balance
|
||||
public func getTransparentBalance(accountIndex: Int) async throws -> WalletBalance {
|
||||
try await blockProcessor.getTransparentBalance(accountIndex: accountIndex)
|
||||
|
@ -838,6 +836,21 @@ extension SDKSynchronizer {
|
|||
}
|
||||
}
|
||||
|
||||
extension SDKSynchronizer {
|
||||
public func getUnifiedAddress(accountIndex: Int) -> UnifiedAddress? {
|
||||
self.initializer.getCurrentAddress(accountIndex: accountIndex)
|
||||
}
|
||||
|
||||
public func getSaplingAddress(accountIndex: Int) -> SaplingAddress? {
|
||||
self.getUnifiedAddress(accountIndex: accountIndex)?.saplingReceiver()
|
||||
}
|
||||
|
||||
public func getTransparentAddress(accountIndex: Int) -> TransparentAddress? {
|
||||
self.getUnifiedAddress(accountIndex: accountIndex)?.transparentReceiver()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
import GRPC
|
||||
extension ConnectionState {
|
||||
init(_ connectivityState: ConnectivityState) {
|
||||
|
|
|
@ -113,11 +113,7 @@ class CompactBlockProcessorTests: XCTestCase {
|
|||
startedScanningNotificationExpectation.subscribe(to: Notification.Name.blockProcessorStartedScanning, object: processor)
|
||||
idleNotificationExpectation.subscribe(to: Notification.Name.blockProcessorIdle, object: processor)
|
||||
|
||||
do {
|
||||
try await processor.start()
|
||||
} catch {
|
||||
XCTFail("shouldn't fail")
|
||||
}
|
||||
await processor.start()
|
||||
}
|
||||
|
||||
// FIXME: disabled see https://github.com/zcash/ZcashLightClientKit/issues/590
|
||||
|
|
|
@ -315,7 +315,8 @@ class BlockBatchValidationTests: XCTestCase {
|
|||
latestHeight: expectedLatestHeight,
|
||||
latestDownloadedHeight: expectedStoreLatestHeight,
|
||||
walletBirthday: walletBirthday
|
||||
)
|
||||
),
|
||||
latestBlockHeight: expectedLatestHeight
|
||||
)
|
||||
let storage = try! TestDbBuilder.inMemoryCompactBlockStorage()
|
||||
let repository = ZcashConsoleFakeStorage(latestBlockHeight: expectedStoreLatestHeight)
|
||||
|
@ -368,7 +369,7 @@ class BlockBatchValidationTests: XCTestCase {
|
|||
XCTAssertTrue(
|
||||
{
|
||||
switch nextBatch {
|
||||
case .processNewBlocks(range: CompactBlockRange(uncheckedBounds: (expectedStoreLatestHeight + 1, expectedLatestHeight))):
|
||||
case .processNewBlocks(range: CompactBlockRange(uncheckedBounds: (expectedStoreLatestHeight + 1, expectedLatestHeight)), latestBlockHeight: expectedLatestHeight):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
|
|
Loading…
Reference in New Issue