Merge pull request #1395 from LukasKorba/public-isSeedRelevantToWallet

Public API isSeedRelevantToWallet
This commit is contained in:
str4d 2024-03-18 14:35:19 +00:00 committed by GitHub
commit 730aee0c5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 36 additions and 2 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {