Skip to content

Commit

Permalink
seedFingerprint and zip32AccountIndex parameters in importAccount added
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasKorba committed Dec 9, 2024
1 parent f69aa19 commit 8c099e3
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 32 deletions.
2 changes: 2 additions & 0 deletions Sources/ZcashLightClientKit/ClosureSynchronizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public protocol ClosureSynchronizer {

func importAccount(

Check warning on line 100 in Sources/ZcashLightClientKit/ClosureSynchronizer.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Function Parameter Count Violation: Function should have 5 parameters or less: it currently has 7 (function_parameter_count)
ufvk: String,
seedFingerprint: [UInt8]?,
zip32AccountIndex: Zip32AccountIndex?,
purpose: AccountPurpose,
name: String,
keySource: String?,
Expand Down
2 changes: 2 additions & 0 deletions Sources/ZcashLightClientKit/CombineSynchronizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public protocol CombineSynchronizer {

func importAccount(

Check warning on line 101 in Sources/ZcashLightClientKit/CombineSynchronizer.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Function Parameter Count Violation: Function should have 5 parameters or less: it currently has 6 (function_parameter_count)
ufvk: String,
seedFingerprint: [UInt8]?,
zip32AccountIndex: Zip32AccountIndex?,
purpose: AccountPurpose,
name: String,
keySource: String?
Expand Down
8 changes: 6 additions & 2 deletions Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ struct ZcashRustBackend: ZcashRustBackendWelding {
@DBActor
func importAccount(
ufvk: String,
seedFingerprint: [UInt8]?,
zip32AccountIndex: Zip32AccountIndex?,
treeState: TreeState,
recoverUntil: UInt32?,
purpose: AccountPurpose,
Expand All @@ -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,
Expand All @@ -153,8 +157,8 @@ struct ZcashRustBackend: ZcashRustBackendWelding {
purpose.rawValue,
[CChar](name.utf8CString),
kSource,
nil,
UINT32_MAX
seedFingerprint,
index
)

guard let uuidPtr else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ protocol ZcashRustBackendWelding {

func importAccount(
ufvk: String,
seedFingerprint: [UInt8]?,
zip32AccountIndex: Zip32AccountIndex?,
treeState: TreeState,
recoverUntil: UInt32?,
purpose: AccountPurpose,
Expand Down
2 changes: 2 additions & 0 deletions Sources/ZcashLightClientKit/Synchronizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ public protocol Synchronizer: AnyObject {
@discardableResult
func importAccount(

Check warning on line 301 in Sources/ZcashLightClientKit/Synchronizer.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Function Parameter Count Violation: Function should have 5 parameters or less: it currently has 6 (function_parameter_count)
ufvk: String,
seedFingerprint: [UInt8]?,
zip32AccountIndex: Zip32AccountIndex?,
purpose: AccountPurpose,
name: String,
keySource: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountUUID, Error>) -> 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
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,21 @@ extension CombineSDKSynchronizer: CombineSynchronizer {

public func importAccount(

Check warning on line 134 in Sources/ZcashLightClientKit/Synchronizer/CombineSDKSynchronizer.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Function Parameter Count Violation: Function should have 5 parameters or less: it currently has 6 (function_parameter_count)
ufvk: String,
seedFingerprint: [UInt8]?,
zip32AccountIndex: Zip32AccountIndex?,
purpose: AccountPurpose,
name: String,
keySource: String?
) async throws -> SinglePublisher<AccountUUID, Error> {
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
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ public class SDKSynchronizer: Synchronizer {
@discardableResult
public func importAccount(
ufvk: String,
seedFingerprint: [UInt8]?,
zip32AccountIndex: Zip32AccountIndex?,
purpose: AccountPurpose,
name: String,
keySource: String?
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit 8c099e3

Please sign in to comment.