Skip to content

Commit

Permalink
Merge pull request #1395 from LukasKorba/public-isSeedRelevantToWallet
Browse files Browse the repository at this point in the history
Public API isSeedRelevantToWallet
  • Loading branch information
str4d authored Mar 18, 2024
2 parents a5a0ef0 + e1c600b commit 730aee0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Sources/ZcashLightClientKit/Synchronizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ public class SDKSynchronizer: Synchronizer {
uri,

Check warning on line 303 in Sources/ZcashLightClientKit/Synchronizer/SDKSynchronizer.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Indentation Width Violation: Code should be indented using one tab or 4 spaces (indentation_width)
accountIndex: accountIndex
)
} catch ZcashError.rustCreateToAddress(let e) {
throw ZcashError.rustProposeTransferFromURI(e)
} catch ZcashError.rustCreateToAddress(let error) {
throw ZcashError.rustProposeTransferFromURI(error)
} catch {
throw error
}
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions Tests/DarksideTests/PaymentURIFulfillmentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down

0 comments on commit 730aee0

Please sign in to comment.