Skip to content

Allow constructing Sh descriptors wrapping an existing Wsh/Wpkh #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,18 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
Ok(Descriptor::Bare(Bare::new(ms)?))
}

// Wrap with sh

/// Create a new sh wrapper for the given wpkh descriptor
pub fn new_sh_with_wpkh(wpkh: Wpkh<Pk>) -> Self {
Descriptor::Sh(Sh::new_with_wpkh(wpkh))
}

/// Create a new sh wrapper for the given wsh descriptor
pub fn new_sh_with_wsh(wsh: Wsh<Pk>) -> Self {
Descriptor::Sh(Sh::new_with_wsh(wsh))
}

// sorted multi

/// Create a new sh sortedmulti descriptor with threshold `k`
Expand Down
14 changes: 14 additions & 0 deletions src/descriptor/sh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
})
}

/// Create a new p2sh wrapper for the given wsh descriptor
pub fn new_with_wsh(wsh: Wsh<Pk>) -> Self {
Self {
inner: ShInner::Wsh(wsh),
}
}

/// Create a new p2sh wrapped wsh sortedmulti descriptor from threshold
/// `k` and Vec of `pks`
pub fn new_wsh_sortedmulti(k: usize, pks: Vec<Pk>) -> Result<Self, Error> {
Expand All @@ -191,6 +198,13 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
inner: ShInner::Wpkh(Wpkh::new(pk)?),
})
}

/// Create a new p2sh wrapper for the given wpkh descriptor
pub fn new_with_wpkh(wpkh: Wpkh<Pk>) -> Self {
Self {
inner: ShInner::Wpkh(wpkh),
}
}
}

impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
Expand Down