@@ -100,6 +100,8 @@ private class BDKService {
100
100
101
101
let documentsDirectoryURL = URL . documentsDirectory
102
102
let walletDataDirectoryURL = documentsDirectoryURL. appendingPathComponent ( " wallet_data " )
103
+ try FileManager . default. ensureDirectoryExists ( at: walletDataDirectoryURL)
104
+ try FileManager . default. removeOldFlatFileIfNeeded ( at: documentsDirectoryURL)
103
105
let persistenceBackendPath = walletDataDirectoryURL. appendingPathComponent ( " wallet.sqlite " )
104
106
. path
105
107
let sqliteStore = try SqliteStore ( path: persistenceBackendPath)
@@ -117,6 +119,8 @@ private class BDKService {
117
119
private func loadWallet( descriptor: Descriptor , changeDescriptor: Descriptor ) throws {
118
120
let documentsDirectoryURL = URL . documentsDirectory
119
121
let walletDataDirectoryURL = documentsDirectoryURL. appendingPathComponent ( " wallet_data " )
122
+ try FileManager . default. ensureDirectoryExists ( at: walletDataDirectoryURL)
123
+ try FileManager . default. removeOldFlatFileIfNeeded ( at: documentsDirectoryURL)
120
124
let persistenceBackendPath = walletDataDirectoryURL. appendingPathComponent ( " wallet.sqlite " )
121
125
. path
122
126
let sqliteStore = try SqliteStore ( path: persistenceBackendPath)
@@ -187,10 +191,14 @@ private class BDKService {
187
191
188
192
private func signAndBroadcast( psbt: Psbt ) throws {
189
193
guard let wallet = self . wallet else { throw WalletError . walletNotFound }
190
- let _ = try wallet. sign ( psbt: psbt)
191
- let transaction = try psbt. extractTx ( )
192
- let client = self . esploraClient
193
- try client. broadcast ( transaction: transaction)
194
+ let isSigned = try wallet. sign ( psbt: psbt)
195
+ if isSigned {
196
+ let transaction = try psbt. extractTx ( )
197
+ let client = self . esploraClient
198
+ try client. broadcast ( transaction: transaction)
199
+ } else {
200
+ throw WalletError . notSigned
201
+ }
194
202
}
195
203
196
204
func syncWithInspector( inspector: SyncScriptInspector ) async throws {
0 commit comments