diff --git a/Sources/ZcashLightClientKit/Synchronizer.swift b/Sources/ZcashLightClientKit/Synchronizer.swift index 2e1788c6..3c400f89 100644 --- a/Sources/ZcashLightClientKit/Synchronizer.swift +++ b/Sources/ZcashLightClientKit/Synchronizer.swift @@ -351,6 +351,11 @@ public protocol Synchronizer: AnyObject { /// - Throws: ZcashError when failures occur and related to `synchronizer.start(retry: Bool)`, it's the only throwing operation /// during the whole endpoint change. func switchTo(endpoint: LightWalletEndpoint) async throws + + /// Checks whether the given seed is relevant to any of the accounts in the wallet. + /// + /// - parameter seed: byte array of the seed + func isSeedRelevantToWallet(seed: [UInt8]) async throws -> Bool } public enum SyncStatus: Equatable { diff --git a/Sources/ZcashLightClientKit/Synchronizer/SDKSynchronizer.swift b/Sources/ZcashLightClientKit/Synchronizer/SDKSynchronizer.swift index a78c5f82..41657487 100644 --- a/Sources/ZcashLightClientKit/Synchronizer/SDKSynchronizer.swift +++ b/Sources/ZcashLightClientKit/Synchronizer/SDKSynchronizer.swift @@ -303,8 +303,8 @@ public class SDKSynchronizer: Synchronizer { uri, accountIndex: accountIndex ) - } catch ZcashError.rustCreateToAddress(let e) { - throw ZcashError.rustProposeTransferFromURI(e) + } catch ZcashError.rustCreateToAddress(let error) { + throw ZcashError.rustProposeTransferFromURI(error) } catch { throw error } @@ -604,6 +604,10 @@ public class SDKSynchronizer: Synchronizer { return subject.eraseToAnyPublisher() } + public func isSeedRelevantToWallet(seed: [UInt8]) async throws -> Bool { + try await initializer.rustBackend.isSeedRelevantToWallet(seed: seed) + } + // MARK: Server switch public func switchTo(endpoint: LightWalletEndpoint) async throws { diff --git a/Tests/DarksideTests/PaymentURIFulfillmentTests.swift b/Tests/DarksideTests/PaymentURIFulfillmentTests.swift index 22f54394..3da93841 100644 --- a/Tests/DarksideTests/PaymentURIFulfillmentTests.swift +++ b/Tests/DarksideTests/PaymentURIFulfillmentTests.swift @@ -315,6 +315,7 @@ class PaymentURIFulfillmentTests: ZcashTestCase { */ let memo = "VGhpcyBpcyBhIHNpbXBsZSBtZW1vLg" // "This is a simple memo." + // swiftlint:disable:next line_length let paymentURI = "zcash:zecIsGreat17mg40levjezevuhdp5pqrd52zere7r7vrjgdwn5sj4xsqtm20euwahv9anxmwr3y3kmwuz8k55a?amount=0.0002&memo=\(memo)&message=Thank%20you%20for%20your%20purchase&label=Your%20Purchase" do { diff --git a/Tests/TestUtils/Sourcery/GeneratedMocks/AutoMockable.generated.swift b/Tests/TestUtils/Sourcery/GeneratedMocks/AutoMockable.generated.swift index 1cba8589..7fddaf26 100644 --- a/Tests/TestUtils/Sourcery/GeneratedMocks/AutoMockable.generated.swift +++ b/Tests/TestUtils/Sourcery/GeneratedMocks/AutoMockable.generated.swift @@ -1800,6 +1800,30 @@ class SynchronizerMock: Synchronizer { try await switchToEndpointClosure!(endpoint) } + // MARK: - isSeedRelevantToWallet + + var isSeedRelevantToWalletSeedThrowableError: Error? + var isSeedRelevantToWalletSeedCallsCount = 0 + var isSeedRelevantToWalletSeedCalled: Bool { + return isSeedRelevantToWalletSeedCallsCount > 0 + } + var isSeedRelevantToWalletSeedReceivedSeed: [UInt8]? + var isSeedRelevantToWalletSeedReturnValue: Bool! + var isSeedRelevantToWalletSeedClosure: (([UInt8]) async throws -> Bool)? + + func isSeedRelevantToWallet(seed: [UInt8]) async throws -> Bool { + if let error = isSeedRelevantToWalletSeedThrowableError { + throw error + } + isSeedRelevantToWalletSeedCallsCount += 1 + isSeedRelevantToWalletSeedReceivedSeed = seed + if let closure = isSeedRelevantToWalletSeedClosure { + return try await closure(seed) + } else { + return isSeedRelevantToWalletSeedReturnValue + } + } + } class TransactionRepositoryMock: TransactionRepository {