From 2e5240d513b325a6373cd5e9efd25eecf5100c9c Mon Sep 17 00:00:00 2001 From: ant013 Date: Wed, 11 Oct 2023 14:25:49 +0600 Subject: [PATCH] Update zcash to 2.0.1, fix initMode --- .../project.pbxproj | 2 +- .../Core/Adapters/ZcashAdapter.swift | 34 +++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj b/UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj index b162652128..2c54e14b5b 100644 --- a/UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj +++ b/UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj @@ -11360,7 +11360,7 @@ repositoryURL = "https://github.com/zcash/ZcashLightClientKit"; requirement = { kind = exactVersion; - version = 2.0.0; + version = 2.0.1; }; }; D3993DAA28F42549008720FB /* XCRemoteSwiftPackageReference "WalletConnectSwiftV2" */ = { diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Adapters/ZcashAdapter.swift b/UnstoppableWallet/UnstoppableWallet/Core/Adapters/ZcashAdapter.swift index 8c6f4f27d3..d4ec54d612 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Adapters/ZcashAdapter.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Adapters/ZcashAdapter.swift @@ -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) // @@ -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) @@ -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, @@ -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, @@ -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) }