@@ -18,6 +18,9 @@ protocol BDKSyncService {
1818 func createWallet( params: String ? ) throws
1919 func loadWallet( ) throws
2020 func deleteWallet( ) throws
21+
22+ func updateNetwork( network: Network )
23+ func updateEsploraURL( _ url: String )
2124}
2225
2326extension BDKSyncService {
@@ -28,7 +31,7 @@ extension BDKSyncService {
2831 throw WalletError . dbNotFound
2932 }
3033
31- let backupInfo = try createBackInfo ( params: params ?? Mnemonic ( wordCount: WordCount . words12) . description)
34+ let backupInfo = try buildBackupInfo ( params: params ?? Mnemonic ( wordCount: WordCount . words12) . description)
3235
3336 try keyClient. saveBackupInfo ( backupInfo)
3437 try keyClient. saveNetwork ( self . network. description)
@@ -46,7 +49,7 @@ extension BDKSyncService {
4649 return wallet
4750 }
4851
49- func createBackInfo ( params: String ) throws -> BackupInfo {
52+ func buildBackupInfo ( params: String ) throws -> BackupInfo {
5053 if isXPub ( params) {
5154 let descriptorPublicKey = try DescriptorPublicKey . fromString ( publicKey: params)
5255 let fingerprint = descriptorPublicKey. masterFingerprint ( )
@@ -127,6 +130,54 @@ extension BDKSyncService {
127130 )
128131 }
129132
133+ func deleteData( ) throws {
134+ do {
135+ try keyClient. deleteAllData ( )
136+
137+ if let bundleID = Bundle . main. bundleIdentifier {
138+ UserDefaults . standard. removePersistentDomain ( forName: bundleID)
139+ }
140+
141+ let walletDataDirectoryURL = URL . walletDataDirectoryURL
142+ if FileManager . default. fileExists ( atPath: walletDataDirectoryURL. path) {
143+ try FileManager . default. removeItem ( at: walletDataDirectoryURL)
144+ }
145+
146+ } catch {
147+ throw AppError . generic ( message: " Failed to remove Keychain data " )
148+ }
149+ }
150+
151+ func loadWalleFromBackup( ) throws -> Wallet {
152+ let backupInfo = try keyClient. getBackupInfo ( )
153+ let descriptor = try Descriptor ( descriptor: backupInfo. descriptor, network: self . network)
154+ let changeDescriptor = try Descriptor (
155+ descriptor: backupInfo. changeDescriptor,
156+ network: self . network
157+ )
158+
159+ try FileManager . default. ensureDirectoryExists ( at: URL . walletDataDirectoryURL)
160+ try FileManager . default. removeOldFlatFileIfNeeded ( at: URL . defaultWalletDirectory)
161+ let persistenceBackendPath = URL . persistenceBackendPath
162+ let connection = try Connection ( path: persistenceBackendPath)
163+
164+ let wallet = try Wallet . load (
165+ descriptor: descriptor,
166+ changeDescriptor: changeDescriptor,
167+ connection: connection
168+ )
169+
170+ return wallet
171+ }
172+
173+ // MARK: - Optionals methods
174+
175+ func updateEsploraURL( _ url: String ) {
176+ // Optional implementation
177+ }
178+
179+ // MARK: - Private
180+
130181 private func isDescriptor( _ param: String ) -> Bool {
131182 param. hasPrefix ( " tr( " ) ||
132183 param. hasPrefix ( " wpkh( " ) ||
0 commit comments