Skip to content
Open
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
6 changes: 3 additions & 3 deletions examples/big.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

use std::collections::HashMap;
use std::str::FromStr;

Check warning on line 14 in examples/big.rs

View workflow job for this annotation

GitHub Actions / Format - nightly toolchain

Diff in /home/runner/work/rust-miniscript/rust-miniscript/examples/big.rs
use bitcoin::{ecdsa, XOnlyPublicKey};
use miniscript::descriptor::Wsh;
use miniscript::policy::{Concrete, Liftable};
use miniscript::policy::{Policy, Liftable};
use miniscript::psbt::PsbtExt;
use miniscript::{
translate_hash_fail, DefiniteDescriptorKey, Descriptor, DescriptorPublicKey, MiniscriptKey,
Expand Down Expand Up @@ -44,7 +44,7 @@
use_descriptor(d);
println!("{:?}", m);

let p = Concrete::<bitcoin::PublicKey>::from_str(&i).unwrap();
let p = Policy::<bitcoin::PublicKey>::from_str(&i).unwrap();
let h = Wsh::new(p.compile().unwrap()).unwrap();
println!("{}", h);
println!("{:?}", h.lift());
Expand All @@ -60,7 +60,7 @@
let sigs = HashMap::<bitcoin::PublicKey, ecdsa::Signature>::new();
d.satisfy(&mut tx.input[0], &sigs).unwrap();

let pol = Concrete::<String>::from_str(&i).unwrap();
let pol = Policy::<String>::from_str(&i).unwrap();
let desc = pol.compile_tr(Some("UNSPENDABLE_KEY".to_string())).unwrap();
println!("{}", desc);
let pk_map = HashMap::new();
Expand Down
4 changes: 2 additions & 2 deletions examples/htlc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
//! Example: Create an HTLC with miniscript using the policy compiler

use std::str::FromStr;

Check warning on line 7 in examples/htlc.rs

View workflow job for this annotation

GitHub Actions / Format - nightly toolchain

Diff in /home/runner/work/rust-miniscript/rust-miniscript/examples/htlc.rs
use miniscript::bitcoin::Network;
use miniscript::descriptor::Wsh;
use miniscript::policy::{Concrete, Liftable};
use miniscript::policy::{Policy, Liftable};

fn main() {
// HTLC policy with 10:1 odds for happy (co-operative) case compared to uncooperative case.
let htlc_policy = Concrete::<bitcoin::PublicKey>::from_str(&format!("or(10@and(sha256({secret_hash}),pk({redeem_identity})),1@and(older({expiry}),pk({refund_identity})))",
let htlc_policy = Policy::<bitcoin::PublicKey>::from_str(&format!("or(10@and(sha256({secret_hash}),pk({redeem_identity})),1@and(older({expiry}),pk({refund_identity})))",
secret_hash = "1111111111111111111111111111111111111111111111111111111111111111",
redeem_identity = "022222222222222222222222222222222222222222222222222222222222222222",
refund_identity = "020202020202020202020202020202020202020202020202020202020202020202",
Expand Down
4 changes: 2 additions & 2 deletions examples/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use miniscript::bitcoin::key::{Keypair, XOnlyPublicKey};
use miniscript::bitcoin::secp256k1::rand;
use miniscript::bitcoin::{Network, WitnessVersion};
use miniscript::descriptor::DescriptorType;
use miniscript::policy::Concrete;
use miniscript::policy::Policy;
use miniscript::{translate_hash_fail, Descriptor, Miniscript, Tap, Translator};

// Refer to https://github.com/sanket1729/adv_btc_workshop/blob/master/workshop.md#creating-a-taproot-descriptor
Expand Down Expand Up @@ -42,7 +42,7 @@ fn main() {
.replace(&[' ', '\n', '\t'][..], "");

let _ms = Miniscript::<String, Tap>::from_str("and_v(v:ripemd160(H),pk(A))").unwrap();
let pol = Concrete::<String>::from_str(&pol_str).unwrap();
let pol = Policy::<String>::from_str(&pol_str).unwrap();
// In case we can't find an internal key for the given policy, we set the internal key to
// a random pubkey as specified by BIP341 (which are *unspendable* by any party :p)
let desc = pol.compile_tr(Some("UNSPENDABLE_KEY".to_string())).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions examples/taptree_of_horror/taptree_of_horror.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bitcoin::transaction::Version;
use bitcoin::{Address, Amount, Network, Psbt, PublicKey, Sequence, TxIn, TxOut};
use helper_fns::{produce_grim_hash, produce_kelly_hash, produce_key_pairs};
use miniscript::descriptor::DescriptorSecretKey;
use miniscript::policy::Concrete;
use miniscript::policy::Policy;
use miniscript::psbt::PsbtExt;
use miniscript::{Descriptor, DescriptorPublicKey};
mod helper_fns;
Expand Down Expand Up @@ -182,7 +182,7 @@ fn main() {
.replace(&[' ', '\n', '\t'][..], "");

// make sure policy doesn't have any issues
let pol = Concrete::<DescriptorPublicKey>::from_str(&pol_str).unwrap();
let pol = Policy::<DescriptorPublicKey>::from_str(&pol_str).unwrap();
let policy_desc: Descriptor<DescriptorPublicKey> = pol.compile_tr(None).unwrap();

// Now, using this public descriptor create the script address
Expand Down
10 changes: 5 additions & 5 deletions src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
//! nightly compiler to run. See the README for exact instructions.
//!

use core::str::FromStr;

Check warning on line 10 in src/benchmarks.rs

View workflow job for this annotation

GitHub Actions / Bench - nightly toolchain

unused import: `core::str::FromStr`

use bitcoin::secp256k1::{Secp256k1, SecretKey};
use test::{black_box, Bencher};

Check warning on line 13 in src/benchmarks.rs

View workflow job for this annotation

GitHub Actions / Bench - nightly toolchain

unused imports: `Bencher` and `black_box`

use crate::descriptor::{SinglePub, SinglePubKey};
use crate::expression::Tree;

Check warning on line 16 in src/benchmarks.rs

View workflow job for this annotation

GitHub Actions / Bench - nightly toolchain

unused import: `crate::expression::Tree`
use crate::{Descriptor, DescriptorPublicKey};

type Desc = Descriptor<DescriptorPublicKey>;

Check warning on line 19 in src/benchmarks.rs

View workflow job for this annotation

GitHub Actions / Bench - nightly toolchain

type alias `Desc` is never used

fn keygen(n: u32) -> DescriptorPublicKey {

Check warning on line 21 in src/benchmarks.rs

View workflow job for this annotation

GitHub Actions / Bench - nightly toolchain

function `keygen` is never used
let secp = Secp256k1::new();

let mut sk = [0; 32];
Expand All @@ -35,7 +35,7 @@
///
/// This method is extremely slow relative to parsing or even re-serializing
/// and should never be called from inside a benchmark.
fn generate_balanced_tree_str<CombFn>(n_nodes: usize, mut combfn: CombFn) -> String

Check warning on line 38 in src/benchmarks.rs

View workflow job for this annotation

GitHub Actions / Bench - nightly toolchain

function `generate_balanced_tree_str` is never used
where
CombFn: FnMut(&str, &str) -> String,
{
Expand Down Expand Up @@ -73,7 +73,7 @@
///
/// This method is extremely slow relative to parsing or even re-serializing
/// and should never be called from inside a benchmark.
fn generate_deep_tree_str<CombFn>(n_nodes: usize, mut combfn: CombFn) -> String

Check warning on line 76 in src/benchmarks.rs

View workflow job for this annotation

GitHub Actions / Bench - nightly toolchain

function `generate_deep_tree_str` is never used
where
CombFn: FnMut(&str, &str) -> String,
{
Expand Down Expand Up @@ -299,20 +299,20 @@

#[cfg(feature = "compiler")]
mod compiler_benches {
use super::*;

Check warning on line 302 in src/benchmarks.rs

View workflow job for this annotation

GitHub Actions / Bench - nightly toolchain

unused import: `super::*`
use crate::descriptor::Descriptor;
use crate::miniscript::Tap;
use crate::policy::compiler::CompilerError;
use crate::policy::Concrete;
use crate::policy::Policy;

Check warning on line 306 in src/benchmarks.rs

View workflow job for this annotation

GitHub Actions / Bench - nightly toolchain

unused import: `crate::policy::Policy`
use crate::prelude::*;
use crate::{Error, Miniscript};

type TapMsRes = Result<Miniscript<String, Tap>, CompilerError>;

Check warning on line 310 in src/benchmarks.rs

View workflow job for this annotation

GitHub Actions / Bench - nightly toolchain

type alias `TapMsRes` is never used
type TapDesc = Result<Descriptor<String>, Error>;

#[bench]
pub fn compile_large_tap(bh: &mut Bencher) {
let pol = Concrete::<String>::from_str(
let pol = Policy::<String>::from_str(
"thresh(20,pk(A),pk(B),pk(C),pk(D),pk(E),pk(F),pk(G),pk(H),pk(I),pk(J),pk(K),pk(L),pk(M),pk(N),pk(O),pk(P),pk(Q),pk(R),pk(S),pk(T),pk(U),pk(V),pk(W),pk(X),pk(Y),pk(Z))",
)
.expect("parsing");
Expand All @@ -325,7 +325,7 @@
#[bench]
pub fn compile_basic(bh: &mut Bencher) {
let h = (0..64).map(|_| "a").collect::<String>();
let pol = Concrete::<String>::from_str(&format!(
let pol = Policy::<String>::from_str(&format!(
"and(thresh(2,and(sha256({}),or(sha256({}),pk(A))),pk(B),pk(C),pk(D),sha256({})),pk(E))",
h, h, h
))
Expand All @@ -339,7 +339,7 @@
#[bench]
pub fn compile_large(bh: &mut Bencher) {
let h = (0..64).map(|_| "a").collect::<String>();
let pol = Concrete::<String>::from_str(
let pol = Policy::<String>::from_str(
&format!("or(pk(L),thresh(9,sha256({}),pk(A),pk(B),and(or(pk(C),pk(D)),pk(E)),after(100),pk(F),pk(G),pk(H),pk(I),and(pk(J),pk(K))))", h)
).expect("parsing");
bh.iter(|| {
Expand All @@ -350,7 +350,7 @@

#[bench]
pub fn compile_xlarge(bh: &mut Bencher) {
let pol = Concrete::<String>::from_str(
let pol = Policy::<String>::from_str(
"or(pk(A),thresh(4,pk(B),older(100),pk(C),and(after(100),or(pk(D),or(pk(E),and(pk(F),thresh(2,pk(G),or(pk(H),and(thresh(5,pk(I),or(pk(J),pk(K)),pk(L),pk(M),pk(N),pk(O),pk(P),pk(Q),pk(R),pk(S),pk(T)),pk(U))),pk(V),or(and(pk(W),pk(X)),pk(Y)),after(100)))))),pk(Z)))"
).expect("parsing");
bh.iter(|| {
Expand Down
9 changes: 4 additions & 5 deletions src/descriptor/bare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ use crate::expression::{self, FromTree};
use crate::miniscript::context::{ScriptContext, ScriptContextError};
use crate::miniscript::satisfy::{Placeholder, Satisfaction, Witness};
use crate::plan::AssetProvider;
use crate::policy::{semantic, Liftable};
use crate::policy::semantic::Semantic;
use crate::policy::Liftable;
use crate::prelude::*;
use crate::util::{varint_len, witness_to_scriptsig};
use crate::{
Expand Down Expand Up @@ -165,7 +166,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Bare<Pk> {
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Bare<Pk> {
fn lift(&self) -> Result<semantic::Policy<Pk>, Error> { self.ms.lift() }
fn lift(&self) -> Result<Semantic<Pk>, Error> { self.ms.lift() }
}

impl<Pk: FromStrKey> FromTree for Bare<Pk> {
Expand Down Expand Up @@ -349,9 +350,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Pkh<Pk> {
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Pkh<Pk> {
fn lift(&self) -> Result<semantic::Policy<Pk>, Error> {
Ok(semantic::Policy::Key(self.pk.clone()))
}
fn lift(&self) -> Result<Semantic<Pk>, Error> { Ok(Semantic::Key(self.pk.clone())) }
}

impl<Pk: FromStrKey> FromTree for Pkh<Pk> {
Expand Down
5 changes: 2 additions & 3 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2075,16 +2075,15 @@ mod tests {
pk([d34db33f/44'/0'/0']xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL/1/*),\
pk(xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL/1),\
pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
let policy: policy::concrete::Policy<DescriptorPublicKey> = descriptor_str.parse().unwrap();
let policy: policy::Policy<DescriptorPublicKey> = descriptor_str.parse().unwrap();
let descriptor = Descriptor::new_sh(policy.compile().unwrap()).unwrap();
let definite_descriptor = descriptor.derive_at_index(42).unwrap();

let res_descriptor_str = "thresh(2,\
pk([d34db33f/44'/0'/0']xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL/1/42),\
pk(xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL/1),\
pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
let res_policy: policy::concrete::Policy<DescriptorPublicKey> =
res_descriptor_str.parse().unwrap();
let res_policy: policy::Policy<DescriptorPublicKey> = res_descriptor_str.parse().unwrap();
let res_descriptor = Descriptor::new_sh(res_policy.compile().unwrap()).unwrap();

assert_eq!(res_descriptor.to_string(), definite_descriptor.to_string());
Expand Down
9 changes: 4 additions & 5 deletions src/descriptor/segwitv0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use crate::miniscript::context::{ScriptContext, ScriptContextError};
use crate::miniscript::limits::MAX_PUBKEYS_PER_MULTISIG;
use crate::miniscript::satisfy::{Placeholder, Satisfaction, Witness};
use crate::plan::AssetProvider;
use crate::policy::{semantic, Liftable};
use crate::policy::semantic::Semantic;
use crate::policy::Liftable;
use crate::prelude::*;
use crate::util::varint_len;
use crate::{
Expand Down Expand Up @@ -182,7 +183,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wsh<Pk> {
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Wsh<Pk> {
fn lift(&self) -> Result<semantic::Policy<Pk>, Error> { self.ms.lift() }
fn lift(&self) -> Result<Semantic<Pk>, Error> { self.ms.lift() }
}

impl<Pk: FromStrKey> crate::expression::FromTree for Wsh<Pk> {
Expand Down Expand Up @@ -394,9 +395,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Wpkh<Pk> {
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Wpkh<Pk> {
fn lift(&self) -> Result<semantic::Policy<Pk>, Error> {
Ok(semantic::Policy::Key(self.pk.clone()))
}
fn lift(&self) -> Result<Semantic<Pk>, Error> { Ok(Semantic::Key(self.pk.clone())) }
}

impl<Pk: FromStrKey> crate::expression::FromTree for Wpkh<Pk> {
Expand Down
7 changes: 4 additions & 3 deletions src/descriptor/sh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use crate::miniscript::context::ScriptContext;
use crate::miniscript::limits::MAX_PUBKEYS_PER_MULTISIG;
use crate::miniscript::satisfy::{Placeholder, Satisfaction};
use crate::plan::AssetProvider;
use crate::policy::{semantic, Liftable};
use crate::policy::semantic::Semantic;
use crate::policy::Liftable;
use crate::prelude::*;
use crate::util::{varint_len, witness_to_scriptsig};
use crate::{
Expand All @@ -47,10 +48,10 @@ pub enum ShInner<Pk: MiniscriptKey> {
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Sh<Pk> {
fn lift(&self) -> Result<semantic::Policy<Pk>, Error> {
fn lift(&self) -> Result<Semantic<Pk>, Error> {
match self.inner {
ShInner::Wsh(ref wsh) => wsh.lift(),
ShInner::Wpkh(ref pk) => Ok(semantic::Policy::Key(pk.as_inner().clone())),
ShInner::Wpkh(ref pk) => Ok(Semantic::Key(pk.as_inner().clone())),
ShInner::Ms(ref ms) => ms.lift(),
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/descriptor/tr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::expression::{self, FromTree};
use crate::miniscript::satisfy::{Placeholder, Satisfaction, SchnorrSigType, Witness};
use crate::miniscript::Miniscript;
use crate::plan::AssetProvider;
use crate::policy::semantic::Policy;
use crate::policy::semantic::Semantic;
use crate::policy::Liftable;
use crate::prelude::*;
use crate::util::{varint_len, witness_size};
Expand Down Expand Up @@ -418,13 +418,13 @@ impl<Pk: MiniscriptKey> fmt::Display for Tr<Pk> {
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Tr<Pk> {
fn lift(&self) -> Result<Policy<Pk>, Error> {
fn lift(&self) -> Result<Semantic<Pk>, Error> {
match &self.tree {
Some(root) => Ok(Policy::Thresh(Threshold::or(
Arc::new(Policy::Key(self.internal_key.clone())),
Some(root) => Ok(Semantic::Thresh(Threshold::or(
Arc::new(Semantic::Key(self.internal_key.clone())),
Arc::new(root.lift()?),
))),
None => Ok(Policy::Key(self.internal_key.clone())),
None => Ok(Semantic::Key(self.internal_key.clone())),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/descriptor/tr/taptree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use core::fmt;
use bitcoin::taproot::{LeafVersion, TapLeafHash, TAPROOT_CONTROL_MAX_NODE_COUNT};

use crate::miniscript::context::Tap;
use crate::policy::{Liftable, Semantic};
use crate::policy::semantic::Semantic;
use crate::policy::Liftable;
use crate::prelude::Vec;
use crate::sync::Arc;
use crate::{Miniscript, MiniscriptKey, Threshold, ToPublicKey};
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@

#[cfg(target_pointer_width = "16")]
compile_error!(
"rust-miniscript currently only supports architectures with pointers wider than 16 bits"

Check warning on line 89 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Format - nightly toolchain

Diff in /home/runner/work/rust-miniscript/rust-miniscript/src/lib.rs
);

pub use bitcoin;
pub use hex;
pub use {bitcoin, hex};

#[cfg(not(feature = "std"))]
#[macro_use]
Expand Down Expand Up @@ -457,7 +456,7 @@
/// Compiler related errors
CompilerError(crate::policy::compiler::CompilerError),
/// Errors related to policy
ConcretePolicy(policy::concrete::PolicyError),
ConcretePolicy(policy::PolicyError),
/// Errors related to lifting
LiftError(policy::LiftError),
/// Forward script context related errors
Expand Down
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ macro_rules! ms_str {
/// `policy_str!("wsh(c:or_i(pk({}),pk({})))", pk1, pk2)`
#[cfg(all(feature = "compiler", test))]
macro_rules! policy_str {
($($arg:tt)*) => ($crate::policy::Concrete::from_str(&format!($($arg)*)).unwrap())
($($arg:tt)*) => ($crate::policy::Policy::from_str(&format!($($arg)*)).unwrap())
}

/// A macro that implements serde serialization and deserialization using the
Expand Down
Loading
Loading