Skip to content

Commit 219119d

Browse files
Add taproot compiler example usage
1 parent 3a2d725 commit 219119d

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ name = "psbt"
4141

4242
[[example]]
4343
name = "xpub_descriptors"
44+
45+
[[example]]
46+
name = "taproot"
47+
required-features = ["compiler"]

examples/taproot.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
extern crate bitcoin;
2+
extern crate miniscript;
3+
4+
#[cfg(feature = "compiler")]
5+
use miniscript::policy::Concrete;
6+
use miniscript::Descriptor;
7+
use std::str::FromStr;
8+
9+
fn main() {
10+
let policies_str = [
11+
"or(1@pk(A),1@pk(B))",
12+
"or(1@and(pk(A),pk(B)),1@pk(C))",
13+
"or(9@or(10@or(1@pk(A),100@pk(D)),1@pk(B)),1@pk(C))",
14+
"or(1@or(1@or(1@pk(A),1@pk(D)),1@pk(B)),1@pk(C))",
15+
"or(1@pk(A),1@or(1@and(pk(B),pk(C)),1@and(pk(D),older(10))))",
16+
"thresh(1,or(1@pk(A),1@pk(B)),or(1@pk(C),1@or(1@and(pk(E),pk(F)),1@pk(D))))",
17+
"thresh(1,pk(Z),and(pk(A),or(1@pk(B),1@pk(C))),pk(D),or(1@or(1@pk(G),1@pk(E)),1@and(pk(F),pk(X))))",
18+
"thresh(1,and(pk(A),or(1@pk(B),1@pk(C))),or(10@pk(D),7@pk(E)),or(2@or(1@pk(F),1@and(pk(G),pk(H))),7@pk(I)))"
19+
];
20+
let unspendable_key = "UNSPENDABLE_KEY".to_string();
21+
let policies: Vec<Concrete<String>> = policies_str
22+
.into_iter()
23+
.map(|x| Concrete::from_str(x).unwrap())
24+
.collect();
25+
let private_comp: Vec<Descriptor<String>> = policies
26+
.iter()
27+
.map(|pol| {
28+
pol.compile_tr_private(Some(unspendable_key.clone()))
29+
.unwrap()
30+
})
31+
.collect();
32+
let default_comp: Vec<Descriptor<String>> = policies
33+
.iter()
34+
.map(|pol| pol.compile_tr(Some(unspendable_key.clone())).unwrap())
35+
.collect();
36+
37+
for idx in 0..policies.len() {
38+
println!("Example {}", idx + 1);
39+
println!("Policy: {}", policies_str[idx]);
40+
println!("Private compilation: {}", private_comp[idx]);
41+
println!("Default compilation: {}\n", default_comp[idx]);
42+
}
43+
}

0 commit comments

Comments
 (0)