Skip to content

Commit b6fe01c

Browse files
Implement XKeyUtils on InnerXKey
Closes #395
1 parent e745122 commit b6fe01c

File tree

1 file changed

+9
-40
lines changed

1 file changed

+9
-40
lines changed

src/descriptor/mod.rs

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
use std::collections::{BTreeMap, HashMap, HashSet};
1818
use std::ops::Deref;
1919

20-
use bitcoin::util::bip32::{
21-
ChildNumber, DerivationPath, ExtendedPrivKey, ExtendedPubKey, Fingerprint, KeySource,
22-
};
20+
use bitcoin::util::bip32::{ChildNumber, DerivationPath, ExtendedPubKey, Fingerprint, KeySource};
2321
use bitcoin::util::psbt;
2422
use bitcoin::{Network, PublicKey, Script, TxOut};
2523

26-
use miniscript::descriptor::{DescriptorPublicKey, DescriptorType, DescriptorXKey, Wildcard};
24+
use miniscript::descriptor::{
25+
DescriptorPublicKey, DescriptorType, DescriptorXKey, InnerXKey, Wildcard,
26+
};
2727
pub use miniscript::{descriptor::KeyMap, Descriptor, Legacy, Miniscript, ScriptContext, Segwitv0};
2828
use miniscript::{DescriptorTrait, ForEachKey, TranslatePk};
2929

@@ -267,41 +267,10 @@ pub(crate) trait XKeyUtils {
267267
fn root_fingerprint(&self, secp: &SecpCtx) -> Fingerprint;
268268
}
269269

270-
// FIXME: `InnerXKey` was made private in rust-miniscript, so we have to implement this manually on
271-
// both `ExtendedPubKey` and `ExtendedPrivKey`.
272-
//
273-
// Revert back to using the trait once https://github.com/rust-bitcoin/rust-miniscript/pull/230 is
274-
// released
275-
impl XKeyUtils for DescriptorXKey<ExtendedPubKey> {
276-
fn full_path(&self, append: &[ChildNumber]) -> DerivationPath {
277-
let full_path = match self.origin {
278-
Some((_, ref path)) => path
279-
.into_iter()
280-
.chain(self.derivation_path.into_iter())
281-
.cloned()
282-
.collect(),
283-
None => self.derivation_path.clone(),
284-
};
285-
286-
if self.wildcard != Wildcard::None {
287-
full_path
288-
.into_iter()
289-
.chain(append.iter())
290-
.cloned()
291-
.collect()
292-
} else {
293-
full_path
294-
}
295-
}
296-
297-
fn root_fingerprint(&self, _: &SecpCtx) -> Fingerprint {
298-
match self.origin {
299-
Some((fingerprint, _)) => fingerprint,
300-
None => self.xkey.fingerprint(),
301-
}
302-
}
303-
}
304-
impl XKeyUtils for DescriptorXKey<ExtendedPrivKey> {
270+
impl<T> XKeyUtils for DescriptorXKey<T>
271+
where
272+
T: InnerXKey,
273+
{
305274
fn full_path(&self, append: &[ChildNumber]) -> DerivationPath {
306275
let full_path = match self.origin {
307276
Some((_, ref path)) => path
@@ -326,7 +295,7 @@ impl XKeyUtils for DescriptorXKey<ExtendedPrivKey> {
326295
fn root_fingerprint(&self, secp: &SecpCtx) -> Fingerprint {
327296
match self.origin {
328297
Some((fingerprint, _)) => fingerprint,
329-
None => self.xkey.fingerprint(secp),
298+
None => self.xkey.xkey_fingerprint(secp),
330299
}
331300
}
332301
}

0 commit comments

Comments
 (0)