From 8c099e3572bd81abd46d59affd640d7e8f51e625 Mon Sep 17 00:00:00 2001 From: Lukas Korba Date: Mon, 9 Dec 2024 13:29:07 +0100 Subject: [PATCH] seedFingerprint and zip32AccountIndex parameters in importAccount added --- .../ClosureSynchronizer.swift | 2 + .../CombineSynchronizer.swift | 2 + .../Rust/ZcashRustBackend.swift | 8 ++- .../Rust/ZcashRustBackendWelding.swift | 2 + .../ZcashLightClientKit/Synchronizer.swift | 2 + .../Synchronizer/ClosureSDKSynchronizer.swift | 11 +++- .../Synchronizer/CombineSDKSynchronizer.swift | 11 +++- .../Synchronizer/SDKSynchronizer.swift | 4 ++ .../AutoMockable.generated.swift | 56 +++++++++---------- 9 files changed, 66 insertions(+), 32 deletions(-) diff --git a/Sources/ZcashLightClientKit/ClosureSynchronizer.swift b/Sources/ZcashLightClientKit/ClosureSynchronizer.swift index 07b75dd1..f04ad0f8 100644 --- a/Sources/ZcashLightClientKit/ClosureSynchronizer.swift +++ b/Sources/ZcashLightClientKit/ClosureSynchronizer.swift @@ -99,6 +99,8 @@ public protocol ClosureSynchronizer { func importAccount( ufvk: String, + seedFingerprint: [UInt8]?, + zip32AccountIndex: Zip32AccountIndex?, purpose: AccountPurpose, name: String, keySource: String?, diff --git a/Sources/ZcashLightClientKit/CombineSynchronizer.swift b/Sources/ZcashLightClientKit/CombineSynchronizer.swift index ae080cad..83434825 100644 --- a/Sources/ZcashLightClientKit/CombineSynchronizer.swift +++ b/Sources/ZcashLightClientKit/CombineSynchronizer.swift @@ -100,6 +100,8 @@ public protocol CombineSynchronizer { func importAccount( ufvk: String, + seedFingerprint: [UInt8]?, + zip32AccountIndex: Zip32AccountIndex?, purpose: AccountPurpose, name: String, keySource: String? diff --git a/Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift b/Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift index bc590a05..ad24cf9b 100644 --- a/Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift +++ b/Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift @@ -122,6 +122,8 @@ struct ZcashRustBackend: ZcashRustBackendWelding { @DBActor func importAccount( ufvk: String, + seedFingerprint: [UInt8]?, + zip32AccountIndex: Zip32AccountIndex?, treeState: TreeState, recoverUntil: UInt32?, purpose: AccountPurpose, @@ -141,6 +143,8 @@ struct ZcashRustBackend: ZcashRustBackendWelding { if let keySource { kSource = [CChar](keySource.utf8CString) } + + let index: UInt32 = zip32AccountIndex?.index ?? UINT32_MAX let uuidPtr = zcashlc_import_account_ufvk( dbData.0, @@ -153,8 +157,8 @@ struct ZcashRustBackend: ZcashRustBackendWelding { purpose.rawValue, [CChar](name.utf8CString), kSource, - nil, - UINT32_MAX + seedFingerprint, + index ) guard let uuidPtr else { diff --git a/Sources/ZcashLightClientKit/Rust/ZcashRustBackendWelding.swift b/Sources/ZcashLightClientKit/Rust/ZcashRustBackendWelding.swift index f0051d43..95625dbc 100644 --- a/Sources/ZcashLightClientKit/Rust/ZcashRustBackendWelding.swift +++ b/Sources/ZcashLightClientKit/Rust/ZcashRustBackendWelding.swift @@ -40,6 +40,8 @@ protocol ZcashRustBackendWelding { func importAccount( ufvk: String, + seedFingerprint: [UInt8]?, + zip32AccountIndex: Zip32AccountIndex?, treeState: TreeState, recoverUntil: UInt32?, purpose: AccountPurpose, diff --git a/Sources/ZcashLightClientKit/Synchronizer.swift b/Sources/ZcashLightClientKit/Synchronizer.swift index 5d439d4f..86d114d1 100644 --- a/Sources/ZcashLightClientKit/Synchronizer.swift +++ b/Sources/ZcashLightClientKit/Synchronizer.swift @@ -300,6 +300,8 @@ public protocol Synchronizer: AnyObject { @discardableResult func importAccount( ufvk: String, + seedFingerprint: [UInt8]?, + zip32AccountIndex: Zip32AccountIndex?, purpose: AccountPurpose, name: String, keySource: String? diff --git a/Sources/ZcashLightClientKit/Synchronizer/ClosureSDKSynchronizer.swift b/Sources/ZcashLightClientKit/Synchronizer/ClosureSDKSynchronizer.swift index 5f9aa290..f3164934 100644 --- a/Sources/ZcashLightClientKit/Synchronizer/ClosureSDKSynchronizer.swift +++ b/Sources/ZcashLightClientKit/Synchronizer/ClosureSDKSynchronizer.swift @@ -86,13 +86,22 @@ extension ClosureSDKSynchronizer: ClosureSynchronizer { public func importAccount( ufvk: String, + seedFingerprint: [UInt8]?, + zip32AccountIndex: Zip32AccountIndex?, purpose: AccountPurpose, name: String, keySource: String?, completion: @escaping (Result) -> Void ) async throws { AsyncToClosureGateway.executeThrowingAction(completion) { - try await self.synchronizer.importAccount(ufvk: ufvk, purpose: purpose, name: name, keySource: keySource) + try await self.synchronizer.importAccount( + ufvk: ufvk, + seedFingerprint: seedFingerprint, + zip32AccountIndex: zip32AccountIndex, + purpose: purpose, + name: name, + keySource: keySource + ) } } diff --git a/Sources/ZcashLightClientKit/Synchronizer/CombineSDKSynchronizer.swift b/Sources/ZcashLightClientKit/Synchronizer/CombineSDKSynchronizer.swift index c3a38a30..169b3731 100644 --- a/Sources/ZcashLightClientKit/Synchronizer/CombineSDKSynchronizer.swift +++ b/Sources/ZcashLightClientKit/Synchronizer/CombineSDKSynchronizer.swift @@ -133,12 +133,21 @@ extension CombineSDKSynchronizer: CombineSynchronizer { public func importAccount( ufvk: String, + seedFingerprint: [UInt8]?, + zip32AccountIndex: Zip32AccountIndex?, purpose: AccountPurpose, name: String, keySource: String? ) async throws -> SinglePublisher { AsyncToCombineGateway.executeThrowingAction() { - try await self.synchronizer.importAccount(ufvk: ufvk, purpose: purpose, name: name, keySource: keySource) + try await self.synchronizer.importAccount( + ufvk: ufvk, + seedFingerprint: seedFingerprint, + zip32AccountIndex: zip32AccountIndex, + purpose: purpose, + name: name, + keySource: keySource + ) } } diff --git a/Sources/ZcashLightClientKit/Synchronizer/SDKSynchronizer.swift b/Sources/ZcashLightClientKit/Synchronizer/SDKSynchronizer.swift index aa5e45d5..22118183 100644 --- a/Sources/ZcashLightClientKit/Synchronizer/SDKSynchronizer.swift +++ b/Sources/ZcashLightClientKit/Synchronizer/SDKSynchronizer.swift @@ -280,6 +280,8 @@ public class SDKSynchronizer: Synchronizer { @discardableResult public func importAccount( ufvk: String, + seedFingerprint: [UInt8]?, + zip32AccountIndex: Zip32AccountIndex?, purpose: AccountPurpose, name: String, keySource: String? @@ -296,6 +298,8 @@ public class SDKSynchronizer: Synchronizer { return try await initializer.rustBackend.importAccount( ufvk: ufvk, + seedFingerprint: seedFingerprint, + zip32AccountIndex: zip32AccountIndex, treeState: checkpoint.treeState(), recoverUntil: chainTip, purpose: purpose, diff --git a/Tests/TestUtils/Sourcery/GeneratedMocks/AutoMockable.generated.swift b/Tests/TestUtils/Sourcery/GeneratedMocks/AutoMockable.generated.swift index fd0ff1bb..0c3f653b 100644 --- a/Tests/TestUtils/Sourcery/GeneratedMocks/AutoMockable.generated.swift +++ b/Tests/TestUtils/Sourcery/GeneratedMocks/AutoMockable.generated.swift @@ -1809,25 +1809,25 @@ class SynchronizerMock: Synchronizer { // MARK: - importAccount - var importAccountUfvkPurposeNameKeySourceThrowableError: Error? - var importAccountUfvkPurposeNameKeySourceCallsCount = 0 - var importAccountUfvkPurposeNameKeySourceCalled: Bool { - return importAccountUfvkPurposeNameKeySourceCallsCount > 0 + var importAccountUfvkSeedFingerprintZip32AccountIndexPurposeNameKeySourceThrowableError: Error? + var importAccountUfvkSeedFingerprintZip32AccountIndexPurposeNameKeySourceCallsCount = 0 + var importAccountUfvkSeedFingerprintZip32AccountIndexPurposeNameKeySourceCalled: Bool { + return importAccountUfvkSeedFingerprintZip32AccountIndexPurposeNameKeySourceCallsCount > 0 } - var importAccountUfvkPurposeNameKeySourceReceivedArguments: (ufvk: String, purpose: AccountPurpose, name: String, keySource: String?)? - var importAccountUfvkPurposeNameKeySourceReturnValue: AccountUUID! - var importAccountUfvkPurposeNameKeySourceClosure: ((String, AccountPurpose, String, String?) async throws -> AccountUUID)? + var importAccountUfvkSeedFingerprintZip32AccountIndexPurposeNameKeySourceReceivedArguments: (ufvk: String, seedFingerprint: [UInt8]?, zip32AccountIndex: Zip32AccountIndex?, purpose: AccountPurpose, name: String, keySource: String?)? + var importAccountUfvkSeedFingerprintZip32AccountIndexPurposeNameKeySourceReturnValue: AccountUUID! + var importAccountUfvkSeedFingerprintZip32AccountIndexPurposeNameKeySourceClosure: ((String, [UInt8]?, Zip32AccountIndex?, AccountPurpose, String, String?) async throws -> AccountUUID)? - func importAccount(ufvk: String, purpose: AccountPurpose, name: String, keySource: String?) async throws -> AccountUUID { - if let error = importAccountUfvkPurposeNameKeySourceThrowableError { + func importAccount(ufvk: String, seedFingerprint: [UInt8]?, zip32AccountIndex: Zip32AccountIndex?, purpose: AccountPurpose, name: String, keySource: String?) async throws -> AccountUUID { + if let error = importAccountUfvkSeedFingerprintZip32AccountIndexPurposeNameKeySourceThrowableError { throw error } - importAccountUfvkPurposeNameKeySourceCallsCount += 1 - importAccountUfvkPurposeNameKeySourceReceivedArguments = (ufvk: ufvk, purpose: purpose, name: name, keySource: keySource) - if let closure = importAccountUfvkPurposeNameKeySourceClosure { - return try await closure(ufvk, purpose, name, keySource) + importAccountUfvkSeedFingerprintZip32AccountIndexPurposeNameKeySourceCallsCount += 1 + importAccountUfvkSeedFingerprintZip32AccountIndexPurposeNameKeySourceReceivedArguments = (ufvk: ufvk, seedFingerprint: seedFingerprint, zip32AccountIndex: zip32AccountIndex, purpose: purpose, name: name, keySource: keySource) + if let closure = importAccountUfvkSeedFingerprintZip32AccountIndexPurposeNameKeySourceClosure { + return try await closure(ufvk, seedFingerprint, zip32AccountIndex, purpose, name, keySource) } else { - return importAccountUfvkPurposeNameKeySourceReturnValue + return importAccountUfvkSeedFingerprintZip32AccountIndexPurposeNameKeySourceReturnValue } } @@ -2438,25 +2438,25 @@ class ZcashRustBackendWeldingMock: ZcashRustBackendWelding { // MARK: - importAccount - var importAccountUfvkTreeStateRecoverUntilPurposeNameKeySourceThrowableError: Error? - var importAccountUfvkTreeStateRecoverUntilPurposeNameKeySourceCallsCount = 0 - var importAccountUfvkTreeStateRecoverUntilPurposeNameKeySourceCalled: Bool { - return importAccountUfvkTreeStateRecoverUntilPurposeNameKeySourceCallsCount > 0 + var importAccountUfvkSeedFingerprintZip32AccountIndexTreeStateRecoverUntilPurposeNameKeySourceThrowableError: Error? + var importAccountUfvkSeedFingerprintZip32AccountIndexTreeStateRecoverUntilPurposeNameKeySourceCallsCount = 0 + var importAccountUfvkSeedFingerprintZip32AccountIndexTreeStateRecoverUntilPurposeNameKeySourceCalled: Bool { + return importAccountUfvkSeedFingerprintZip32AccountIndexTreeStateRecoverUntilPurposeNameKeySourceCallsCount > 0 } - var importAccountUfvkTreeStateRecoverUntilPurposeNameKeySourceReceivedArguments: (ufvk: String, treeState: TreeState, recoverUntil: UInt32?, purpose: AccountPurpose, name: String, keySource: String?)? - var importAccountUfvkTreeStateRecoverUntilPurposeNameKeySourceReturnValue: AccountUUID! - var importAccountUfvkTreeStateRecoverUntilPurposeNameKeySourceClosure: ((String, TreeState, UInt32?, AccountPurpose, String, String?) async throws -> AccountUUID)? + var importAccountUfvkSeedFingerprintZip32AccountIndexTreeStateRecoverUntilPurposeNameKeySourceReceivedArguments: (ufvk: String, seedFingerprint: [UInt8]?, zip32AccountIndex: Zip32AccountIndex?, treeState: TreeState, recoverUntil: UInt32?, purpose: AccountPurpose, name: String, keySource: String?)? + var importAccountUfvkSeedFingerprintZip32AccountIndexTreeStateRecoverUntilPurposeNameKeySourceReturnValue: AccountUUID! + var importAccountUfvkSeedFingerprintZip32AccountIndexTreeStateRecoverUntilPurposeNameKeySourceClosure: ((String, [UInt8]?, Zip32AccountIndex?, TreeState, UInt32?, AccountPurpose, String, String?) async throws -> AccountUUID)? - func importAccount(ufvk: String, treeState: TreeState, recoverUntil: UInt32?, purpose: AccountPurpose, name: String, keySource: String?) async throws -> AccountUUID { - if let error = importAccountUfvkTreeStateRecoverUntilPurposeNameKeySourceThrowableError { + func importAccount(ufvk: String, seedFingerprint: [UInt8]?, zip32AccountIndex: Zip32AccountIndex?, treeState: TreeState, recoverUntil: UInt32?, purpose: AccountPurpose, name: String, keySource: String?) async throws -> AccountUUID { + if let error = importAccountUfvkSeedFingerprintZip32AccountIndexTreeStateRecoverUntilPurposeNameKeySourceThrowableError { throw error } - importAccountUfvkTreeStateRecoverUntilPurposeNameKeySourceCallsCount += 1 - importAccountUfvkTreeStateRecoverUntilPurposeNameKeySourceReceivedArguments = (ufvk: ufvk, treeState: treeState, recoverUntil: recoverUntil, purpose: purpose, name: name, keySource: keySource) - if let closure = importAccountUfvkTreeStateRecoverUntilPurposeNameKeySourceClosure { - return try await closure(ufvk, treeState, recoverUntil, purpose, name, keySource) + importAccountUfvkSeedFingerprintZip32AccountIndexTreeStateRecoverUntilPurposeNameKeySourceCallsCount += 1 + importAccountUfvkSeedFingerprintZip32AccountIndexTreeStateRecoverUntilPurposeNameKeySourceReceivedArguments = (ufvk: ufvk, seedFingerprint: seedFingerprint, zip32AccountIndex: zip32AccountIndex, treeState: treeState, recoverUntil: recoverUntil, purpose: purpose, name: name, keySource: keySource) + if let closure = importAccountUfvkSeedFingerprintZip32AccountIndexTreeStateRecoverUntilPurposeNameKeySourceClosure { + return try await closure(ufvk, seedFingerprint, zip32AccountIndex, treeState, recoverUntil, purpose, name, keySource) } else { - return importAccountUfvkTreeStateRecoverUntilPurposeNameKeySourceReturnValue + return importAccountUfvkSeedFingerprintZip32AccountIndexTreeStateRecoverUntilPurposeNameKeySourceReturnValue } }