Skip to content

Commit 42367cf

Browse files
authored
Merge pull request #232 from sanket1729/expose_inner
Expose sh/wsh Inners
2 parents 34a73ec + de0e937 commit 42367cf

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "miniscript"
3-
version = "5.0.2"
3+
version = "5.1.0"
44
authors = ["Andrew Poelstra <[email protected]>, Sanket Kanjalkar <[email protected]>"]
55
repository = "https://github.com/apoelstra/miniscript"
66
description = "Miniscript: a subset of Bitcoin Script designed for analysis"

examples/parse.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
extern crate bitcoin;
1818
extern crate miniscript;
1919

20-
use miniscript::DescriptorTrait;
20+
use miniscript::{descriptor::DescriptorType, DescriptorTrait};
2121
use std::str::FromStr;
2222

2323
fn main() {
@@ -45,4 +45,11 @@ fn main() {
4545
format!("{:x}", my_descriptor.explicit_script()),
4646
"21020202020202020202020202020202020202020202020202020202020202020202ac"
4747
);
48+
49+
let desc = miniscript::Descriptor::<bitcoin::PublicKey>::from_str(
50+
"sh(wsh(c:pk_k(020202020202020202020202020202020202020202020202020202020202020202)))",
51+
)
52+
.unwrap();
53+
54+
assert!(desc.desc_type() == DescriptorType::ShWsh);
4855
}

src/descriptor/mod.rs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ mod sh;
4747
mod sortedmulti;
4848
// Descriptor Exports
4949
pub use self::bare::{Bare, Pkh};
50-
pub use self::segwitv0::{Wpkh, Wsh};
51-
pub use self::sh::Sh;
50+
pub use self::segwitv0::{Wpkh, Wsh, WshInner};
51+
pub use self::sh::{Sh, ShInner};
5252
pub use self::sortedmulti::SortedMultiVec;
5353

5454
mod checksum;
@@ -168,6 +168,31 @@ pub enum Descriptor<Pk: MiniscriptKey> {
168168
Wsh(Wsh<Pk>),
169169
}
170170

171+
/// Descriptor Type of the descriptor
172+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
173+
pub enum DescriptorType {
174+
/// Bare descriptor(Contains the native P2pk)
175+
Bare,
176+
/// Pure Sh Descriptor. Does not contain nested Wsh/Wpkh
177+
Sh,
178+
/// Pkh Descriptor
179+
Pkh,
180+
/// Wpkh Descriptor
181+
Wpkh,
182+
/// Wsh
183+
Wsh,
184+
/// Sh Wrapped Wsh
185+
ShWsh,
186+
/// Sh wrapped Wpkh
187+
ShWpkh,
188+
/// Sh Sorted Multi
189+
ShSortedMulti,
190+
/// Wsh Sorted Multi
191+
WshSortedMulti,
192+
/// Sh Wsh Sorted Multi
193+
ShWshSortedMulti,
194+
}
195+
171196
impl<Pk: MiniscriptKey> Descriptor<Pk> {
172197
// Keys
173198

@@ -251,6 +276,28 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
251276
pub fn new_wsh_sortedmulti(k: usize, pks: Vec<Pk>) -> Result<Self, Error> {
252277
Ok(Descriptor::Wsh(Wsh::new_sortedmulti(k, pks)?))
253278
}
279+
280+
/// Get the [DescriptorType] of [Descriptor]
281+
pub fn desc_type(&self) -> DescriptorType {
282+
match *self {
283+
Descriptor::Bare(ref _bare) => DescriptorType::Bare,
284+
Descriptor::Pkh(ref _pkh) => DescriptorType::Pkh,
285+
Descriptor::Wpkh(ref _wpkh) => DescriptorType::Wpkh,
286+
Descriptor::Sh(ref sh) => match sh.as_inner() {
287+
ShInner::Wsh(ref wsh) => match wsh.as_inner() {
288+
WshInner::SortedMulti(ref _smv) => DescriptorType::ShWshSortedMulti,
289+
WshInner::Ms(ref _ms) => DescriptorType::ShWsh,
290+
},
291+
ShInner::Wpkh(ref _wpkh) => DescriptorType::ShWpkh,
292+
ShInner::SortedMulti(ref _smv) => DescriptorType::ShSortedMulti,
293+
ShInner::Ms(ref _ms) => DescriptorType::Sh,
294+
},
295+
Descriptor::Wsh(ref wsh) => match wsh.as_inner() {
296+
WshInner::SortedMulti(ref _smv) => DescriptorType::WshSortedMulti,
297+
WshInner::Ms(ref _ms) => DescriptorType::Wsh,
298+
},
299+
}
300+
}
254301
}
255302

256303
impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Descriptor<P> {

0 commit comments

Comments
 (0)