Skip to content

Commit

Permalink
Update zcash to 2.0.1, fix initMode
Browse files Browse the repository at this point in the history
  • Loading branch information
ant013 committed Oct 13, 2023
1 parent c81093b commit 2e5240d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11360,7 +11360,7 @@
repositoryURL = "https://github.com/zcash/ZcashLightClientKit";
requirement = {
kind = exactVersion;
version = 2.0.0;
version = 2.0.1;
};
};
D3993DAA28F42549008720FB /* XCRemoteSwiftPackageReference "WalletConnectSwiftV2" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,6 @@ class ZcashAdapter {

private(set) var syncing: Bool = true

private func defaultFee(network: ZcashNetwork, height: Int? = nil) -> Zatoshi {
network.constants.defaultFee(for: height ?? BlockHeight.max)
}

private func defaultFeeDecimal(network: ZcashNetwork, height: Int? = nil) -> Decimal {
// todo update fee settings
fee// defaultFee(network: network, height: height).decimalValue.decimalValue
}

init(wallet: Wallet, restoreSettings: RestoreSettings) throws {
logger = App.shared.logger.scoped(with: "ZCashKit") // HsToolKit.Logger(minLogLevel: .debug) //

Expand All @@ -84,23 +75,28 @@ class ZcashAdapter {
network = ZcashNetworkBuilder.network(for: .mainnet)

// todo: update fee settings
fee = Zatoshi(10_000).decimalValue.decimalValue//network.constants.defaultFee().decimalValue.decimalValue
fee = network.constants.defaultFee().decimalValue.decimalValue

token = wallet.token
transactionSource = wallet.transactionSource
uniqueId = wallet.account.id

var existingMode: WalletInitMode?
if let dbUrl = try? Self.spendParamsURL(uniqueId: uniqueId),
Self.exist(url: dbUrl) {
existingMode = .existingWallet
}
switch wallet.account.origin {
case .created:
birthday = Self.newBirthdayHeight(network: network)
initMode = .newWallet
initMode = existingMode ?? .newWallet
case .restored:
if let height = restoreSettings.birthdayHeight {
birthday = max(height, network.constants.saplingActivationHeight)
} else {
birthday = network.constants.saplingActivationHeight
}
initMode = .restoreWallet
initMode = existingMode ?? .restoreWallet
}

let seedData = [UInt8](seed)
Expand Down Expand Up @@ -360,7 +356,7 @@ class ZcashAdapter {
blockHeight: transaction.minedHeight,
confirmationsThreshold: ZcashSDK.defaultRewindDistance,
date: Date(timeIntervalSince1970: Double(transaction.timestamp)),
fee: defaultFeeDecimal(network: network, height: transaction.minedHeight),
fee: transaction.fee?.decimalValue.decimalValue,
failed: transaction.failed,
lockInfo: nil,
conflictingHash: nil,
Expand All @@ -379,7 +375,7 @@ class ZcashAdapter {
blockHeight: transaction.minedHeight,
confirmationsThreshold: ZcashSDK.defaultRewindDistance,
date: Date(timeIntervalSince1970: Double(transaction.timestamp)),
fee: defaultFeeDecimal(network: network, height: transaction.minedHeight),
fee: transaction.fee?.decimalValue.decimalValue,
failed: transaction.failed,
lockInfo: nil,
conflictingHash: nil,
Expand Down Expand Up @@ -531,6 +527,16 @@ extension ZcashAdapter {
return url
}

private static func exist(url: URL) -> Bool {
let fileManager = FileManager.default

do {
return try fileManager.fileExists(coordinatingAccessAt: url).exists
} catch {
return false
}
}

private static func fsBlockDbRootURL(uniqueId: String, network: ZcashNetwork) throws -> URL {
try dataDirectoryUrl().appendingPathComponent(network.networkType.chainName + uniqueId + ZcashSDK.defaultFsCacheName, isDirectory: true)
}
Expand Down

0 comments on commit 2e5240d

Please sign in to comment.