@@ -164,34 +164,27 @@ private class BDKService {
164
164
throw WalletError . walletNotFound
165
165
}
166
166
167
- let descriptor : Descriptor
168
- let changeDescriptor : Descriptor
169
-
170
- let cleanDescriptorString = descriptorString. components ( separatedBy: " \n " )
167
+ let descriptorStrings = descriptorString. components ( separatedBy: " \n " )
171
168
. map { $0. split ( separator: " # " ) . first? . trimmingCharacters ( in: . whitespaces) ?? " " }
172
169
. filter { !$0. isEmpty }
173
- . joined ( separator: " \n " )
174
-
175
- if let firstDescriptor = try ? Descriptor (
176
- descriptor: cleanDescriptorString. components ( separatedBy: " \n " ) [ 0 ] ,
177
- network: network
178
- ) ,
179
- firstDescriptor. isMultipath ( )
180
- {
181
- let baseDescriptor = cleanDescriptorString. components ( separatedBy: " \n " ) [ 0 ]
182
- descriptor = try Descriptor (
183
- descriptor: baseDescriptor. replacingOccurrences ( of: " <0;1> " , with: " 0 " ) ,
184
- network: network
185
- )
186
- changeDescriptor = try Descriptor (
187
- descriptor: baseDescriptor. replacingOccurrences ( of: " <0;1> " , with: " 1 " ) ,
170
+ let descriptor : Descriptor
171
+ let changeDescriptor : Descriptor
172
+ if descriptorStrings. count == 1 {
173
+ let parsedDescriptor = try Descriptor (
174
+ descriptor: descriptorStrings [ 0 ] ,
188
175
network: network
189
176
)
177
+ let singleDescriptors = try parsedDescriptor. toSingleDescriptors ( )
178
+ guard singleDescriptors. count >= 2 else {
179
+ throw WalletError . walletNotFound
180
+ }
181
+ descriptor = singleDescriptors [ 0 ]
182
+ changeDescriptor = singleDescriptors [ 1 ]
183
+ } else if descriptorStrings. count == 2 {
184
+ descriptor = try Descriptor ( descriptor: descriptorStrings [ 0 ] , network: network)
185
+ changeDescriptor = try Descriptor ( descriptor: descriptorStrings [ 1 ] , network: network)
190
186
} else {
191
- let descriptors = cleanDescriptorString. components ( separatedBy: " \n " )
192
- guard descriptors. count == 2 else { throw WalletError . walletNotFound }
193
- descriptor = try Descriptor ( descriptor: descriptors [ 0 ] , network: network)
194
- changeDescriptor = try Descriptor ( descriptor: descriptors [ 1 ] , network: network)
187
+ throw WalletError . walletNotFound
195
188
}
196
189
197
190
let backupInfo = BackupInfo (
0 commit comments