Skip to content

Commit bb63808

Browse files
committed
Merge #303: Update derived_descriptor signature and related examples
2a695f8 Update derived_descriptor signature and related examples (eunoia_1729) Pull request description: ## Description Resolves #302. - Updates the order of parameters in `derived_descriptor` function signature. - Updates the P2WSH-P2SH and ranged xpub examples to call `derived_descriptor` function. ACKs for top commit: apoelstra: ACK 2a695f8 sanket1729: ACK 2a695f8 Tree-SHA512: 1ceb1141e6d6e42c22eba4030d5696514f7727cab5025e08ddf15fff895796d5392e8929383583f7d3d125fdef867aa6a59937cfc7580302b9bf392ceeb8da7f
2 parents 69e7c4d + 2a695f8 commit bb63808

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

examples/xpub_descriptors.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,15 @@ fn main() {
5151
"sh(wsh(sortedmulti(1,xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB/1/0/*,xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH/0/0/*)))",
5252
)
5353
.unwrap()
54-
.derive(5)
55-
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))
54+
.derived_descriptor(&secp_ctx, 5)
5655
.unwrap()
5756
.address(bitcoin::Network::Bitcoin).unwrap();
5857

5958
let addr_two = Descriptor::<DescriptorPublicKey>::from_str(
6059
"sh(wsh(sortedmulti(1,xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH/0/0/*,xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB/1/0/*)))",
6160
)
6261
.unwrap()
63-
.derive(5)
64-
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))
62+
.derived_descriptor(&secp_ctx, 5)
6563
.unwrap()
6664
.address(bitcoin::Network::Bitcoin).unwrap();
6765
let expected = bitcoin::Address::from_str("325zcVBN5o2eqqqtGwPjmtDd8dJRyYP82s").unwrap();

src/descriptor/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ impl Descriptor<DescriptorPublicKey> {
581581
/// let secp = secp256k1::Secp256k1::verification_only();
582582
/// let descriptor = Descriptor::<DescriptorPublicKey>::from_str("tr(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/0/*)")
583583
/// .expect("Valid ranged descriptor");
584-
/// let result = descriptor.derived_descriptor(0, &secp).expect("Non-hardened derivation");
584+
/// let result = descriptor.derived_descriptor(&secp, 0).expect("Non-hardened derivation");
585585
/// assert_eq!(result.to_string(), "tr(03cc8a4bc64d897bddc5fbc2f670f7a8ba0b386779106cf1223c6fc5d7cd6fc115)#6qm9h8ym");
586586
/// ```
587587
///
@@ -590,8 +590,8 @@ impl Descriptor<DescriptorPublicKey> {
590590
/// This function will return an error if hardened derivation is attempted.
591591
pub fn derived_descriptor<C: secp256k1::Verification>(
592592
&self,
593-
index: u32,
594593
secp: &secp256k1::Secp256k1<C>,
594+
index: u32,
595595
) -> Result<Descriptor<bitcoin::PublicKey>, ConversionError> {
596596
let derived = self
597597
.derive(index)

0 commit comments

Comments
 (0)