Skip to content

Commit 239e61e

Browse files
committed
Merge #299: Allow constructing Sh descriptors wrapping an existing Wsh/Wpkh
bd7c642 Allow constructing Sh descriptors wrapping an existing Wsh/Wpkh (Nadav Ivgi) Pull request description: Useful if you already have an `W{s,pk}h` descriptor and wish to wrap it with P2SH. This used to be [possible](https://github.com/shesek/minsc/blob/33433462e84e3903a70a9aac6f47e591df094127/src/stdlib/miniscript.rs#L149-L153) before the new inner types for the Descriptor enum variants, which has private fields that cannot be initialized externally. ACKs for top commit: apoelstra: ACK bd7c642 sanket1729: ACK bd7c642 Tree-SHA512: c89f77d4cc8bcbda39f48361fc0693a7731ab2202f487dace44ab612fcdbd011476e6fbe79f1d429f10f9b1ea7e8ea1b164592e77e901030cec39f82dd764c02
2 parents bb63808 + bd7c642 commit 239e61e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/descriptor/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,18 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
277277
Ok(Descriptor::Bare(Bare::new(ms)?))
278278
}
279279

280+
// Wrap with sh
281+
282+
/// Create a new sh wrapper for the given wpkh descriptor
283+
pub fn new_sh_with_wpkh(wpkh: Wpkh<Pk>) -> Self {
284+
Descriptor::Sh(Sh::new_with_wpkh(wpkh))
285+
}
286+
287+
/// Create a new sh wrapper for the given wsh descriptor
288+
pub fn new_sh_with_wsh(wsh: Wsh<Pk>) -> Self {
289+
Descriptor::Sh(Sh::new_with_wsh(wsh))
290+
}
291+
280292
// sorted multi
281293

282294
/// Create a new sh sortedmulti descriptor with threshold `k`

src/descriptor/sh.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
175175
})
176176
}
177177

178+
/// Create a new p2sh wrapper for the given wsh descriptor
179+
pub fn new_with_wsh(wsh: Wsh<Pk>) -> Self {
180+
Self {
181+
inner: ShInner::Wsh(wsh),
182+
}
183+
}
184+
178185
/// Create a new p2sh wrapped wsh sortedmulti descriptor from threshold
179186
/// `k` and Vec of `pks`
180187
pub fn new_wsh_sortedmulti(k: usize, pks: Vec<Pk>) -> Result<Self, Error> {
@@ -191,6 +198,13 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
191198
inner: ShInner::Wpkh(Wpkh::new(pk)?),
192199
})
193200
}
201+
202+
/// Create a new p2sh wrapper for the given wpkh descriptor
203+
pub fn new_with_wpkh(wpkh: Wpkh<Pk>) -> Self {
204+
Self {
205+
inner: ShInner::Wpkh(wpkh),
206+
}
207+
}
194208
}
195209

196210
impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {

0 commit comments

Comments
 (0)