|
14 | 14 | //! This module contains generic utilities to work with descriptors, plus some re-exported types
|
15 | 15 | //! from [`miniscript`].
|
16 | 16 |
|
17 |
| -use std::collections::{BTreeMap, HashSet}; |
| 17 | +use std::collections::BTreeMap; |
18 | 18 | use std::ops::Deref;
|
19 | 19 |
|
20 | 20 | use bitcoin::util::bip32::{ChildNumber, DerivationPath, ExtendedPubKey, Fingerprint, KeySource};
|
@@ -222,23 +222,9 @@ pub(crate) fn into_wallet_descriptor_checked<T: IntoWalletDescriptor>(
|
222 | 222 | return Err(DescriptorError::HardenedDerivationXpub);
|
223 | 223 | }
|
224 | 224 |
|
225 |
| - // Ensure that there are no duplicated keys |
226 |
| - let mut found_keys = HashSet::new(); |
227 |
| - let descriptor_contains_duplicated_keys = descriptor.for_any_key(|k| { |
228 |
| - if let DescriptorPublicKey::XPub(xkey) = k.as_key() { |
229 |
| - let fingerprint = xkey.root_fingerprint(secp); |
230 |
| - if found_keys.contains(&fingerprint) { |
231 |
| - return true; |
232 |
| - } |
233 |
| - |
234 |
| - found_keys.insert(fingerprint); |
235 |
| - } |
236 |
| - |
237 |
| - false |
238 |
| - }); |
239 |
| - if descriptor_contains_duplicated_keys { |
240 |
| - return Err(DescriptorError::DuplicatedKeys); |
241 |
| - } |
| 225 | + // Run miniscript's sanity check, which will look for duplicated keys and other potential |
| 226 | + // issues |
| 227 | + descriptor.sanity_check()?; |
242 | 228 |
|
243 | 229 | Ok((descriptor, keymap))
|
244 | 230 | }
|
@@ -923,14 +909,10 @@ mod test {
|
923 | 909 | DescriptorError::HardenedDerivationXpub
|
924 | 910 | ));
|
925 | 911 |
|
926 |
| - let descriptor = "wsh(multi(2,tpubD6NzVbkrYhZ4XHndKkuB8FifXm8r5FQHwrN6oZuWCz13qb93rtgKvD4PQsqC4HP4yhV3tA2fqr2RbY5mNXfM7RxXUoeABoDtsFUq2zJq6YK/0/*,tpubD6NzVbkrYhZ4XHndKkuB8FifXm8r5FQHwrN6oZuWCz13qb93rtgKvD4PQsqC4HP4yhV3tA2fqr2RbY5mNXfM7RxXUoeABoDtsFUq2zJq6YK/1/*))"; |
| 912 | + let descriptor = "wsh(multi(2,tpubD6NzVbkrYhZ4XHndKkuB8FifXm8r5FQHwrN6oZuWCz13qb93rtgKvD4PQsqC4HP4yhV3tA2fqr2RbY5mNXfM7RxXUoeABoDtsFUq2zJq6YK/0/*,tpubD6NzVbkrYhZ4XHndKkuB8FifXm8r5FQHwrN6oZuWCz13qb93rtgKvD4PQsqC4HP4yhV3tA2fqr2RbY5mNXfM7RxXUoeABoDtsFUq2zJq6YK/0/*))"; |
927 | 913 | let result = into_wallet_descriptor_checked(descriptor, &secp, Network::Testnet);
|
928 | 914 |
|
929 | 915 | assert!(result.is_err());
|
930 |
| - assert!(matches!( |
931 |
| - result.unwrap_err(), |
932 |
| - DescriptorError::DuplicatedKeys |
933 |
| - )); |
934 | 916 | }
|
935 | 917 |
|
936 | 918 | #[test]
|
|
0 commit comments