Skip to content

Commit 0efbece

Browse files
committed
Merge #542: Implement XKeyUtils on InnerXKey
b6fe01c Implement XKeyUtils on InnerXKey (Gianluca Acerbis) Pull request description: Closes #395 <!-- You can erase any parts of this template not applicable to your Pull Request. --> ### Description <!-- Describe the purpose of this PR, what's being adding and/or fixed --> ### Notes to the reviewers <!-- In this section you can include notes directed to the reviewers, like explaining why some parts of the PR were done in a specific way --> ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### New Features: * [ ] I've added tests for the new feature * [ ] I've added docs for the new feature * [ ] I've updated `CHANGELOG.md` #### Bugfixes: * [ ] This pull request breaks the existing API * [ ] I've added tests to reproduce the issue which are now passing * [x] I'm linking the issue being fixed by this PR ACKs for top commit: danielabrozzoni: ACK b6fe01c - the code looks good to me, I tested locally and all tests pass notmandatory: ACK b6fe01c Tree-SHA512: 00a3ed9532a0589ac4be55a7d0c6ac5251f03f716adb2086eb934d9a9b04bcb7fd95aaeba38b68c5c90876644ce53ac5e39a912a4096e789887342f8727ae434
2 parents e745122 + b6fe01c commit 0efbece

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)