Closes #406 This commits differences how Checkpoints are retrieved from the resource bundle depending on the target platform.
This commit is contained in:
parent
79dbe8f387
commit
b6bb17ab8b
|
@ -9,11 +9,13 @@ import Foundation
|
|||
|
||||
public extension WalletBirthday {
|
||||
static func birthday(with height: BlockHeight, network: ZcashNetwork) -> WalletBirthday {
|
||||
let checkpointDirectoryURL = BundleCheckpointURLProvider.default.url(network.networkType)
|
||||
|
||||
switch network.networkType {
|
||||
case .mainnet:
|
||||
return birthday(with: height, checkpointDirectory: Self.mainnetCheckpointDirectory) ?? .mainnetMin
|
||||
return birthday(with: height, checkpointDirectory: checkpointDirectoryURL) ?? .mainnetMin
|
||||
case .testnet:
|
||||
return birthday(with: height, checkpointDirectory: Self.testnetCheckpointDirectory) ?? .testnetMin
|
||||
return birthday(with: height, checkpointDirectory: checkpointDirectoryURL) ?? .testnetMin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,3 +58,56 @@ extension WalletBirthday {
|
|||
return checkpoint
|
||||
}
|
||||
}
|
||||
|
||||
struct BundleCheckpointURLProvider {
|
||||
var url: (NetworkType) -> URL
|
||||
}
|
||||
|
||||
|
||||
extension BundleCheckpointURLProvider {
|
||||
|
||||
/// Attempts to resolve the platform by checking `#if os(macOS)` build corresponds to a MacOS target
|
||||
/// `#else` branch of that condition will assume iOS is the target platform
|
||||
static var `default` = BundleCheckpointURLProvider { networkType in
|
||||
#if os(macOS)
|
||||
Self.macOS.url(networkType)
|
||||
#else
|
||||
Self.iOS.url(networkType)
|
||||
#endif
|
||||
}
|
||||
|
||||
static var iOS = BundleCheckpointURLProvider(url: { networkType in
|
||||
switch networkType {
|
||||
case .mainnet:
|
||||
return WalletBirthday.mainnetCheckpointDirectory
|
||||
case .testnet:
|
||||
return WalletBirthday.testnetCheckpointDirectory
|
||||
}
|
||||
})
|
||||
|
||||
/// This variant attempts to retrieve the saplingActivation checkpoint for the given network type
|
||||
/// using `Bundle.module.url(forResource:withExtension:subdirectory:localization)`
|
||||
/// if not found it will return `WalletBirthday.mainnetCheckpointDirectory` or
|
||||
/// `WalletBirthday.testnetCheckpointDirectory`. This responds to tests
|
||||
/// failing on MacOS target because the checkpoint resources would fail.
|
||||
static var macOS = BundleCheckpointURLProvider(url: { networkType in
|
||||
switch networkType {
|
||||
case .mainnet:
|
||||
return Bundle.module.url(
|
||||
forResource: "419200",
|
||||
withExtension: "json",
|
||||
subdirectory: "checkpoints/mainnet/",
|
||||
localization: nil
|
||||
)?
|
||||
.deletingLastPathComponent() ?? WalletBirthday.mainnetCheckpointDirectory
|
||||
case .testnet:
|
||||
return Bundle.module.url(
|
||||
forResource: "280000",
|
||||
withExtension: "json",
|
||||
subdirectory: "checkpoints/testnet/",
|
||||
localization: nil
|
||||
)?
|
||||
.deletingLastPathComponent() ?? WalletBirthday.testnetCheckpointDirectory
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -15,5 +15,4 @@ extension WalletBirthday {
|
|||
)
|
||||
|
||||
static let mainnetCheckpointDirectory = Bundle.module.bundleURL.appendingPathComponent("checkpoints/mainnet/")
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue