Skip to content

Commit c5af7c8

Browse files
committed
Allow constructing Sh descriptors wrapping an existing Wsh/Wpkh
1 parent 6a89bd0 commit c5af7c8

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)