Skip to content

Commit 1c823e6

Browse files
authored
Merge pull request #566 from apoelstra/2023-07--recursion-9.x
2 parents 424a57a + f1c1272 commit 1c823e6

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 9.0.2 - July 13, 2023
2+
3+
- Workaround for recursion bug in rustc https://github.com/rust-bitcoin/rust-miniscript/pull/566
4+
15
# 9.0.1 - March 8, 2023
26

37
- Fixed a typing rule in `multi_a` for taproot miniscript descriptors. Current typing rules

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "miniscript"
3-
version = "9.0.1"
3+
version = "9.0.2"
44
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>, Sanket Kanjalkar <sanket1729@gmail.com>"]
55
license = "CC0-1.0"
66
homepage = "https://github.com/rust-bitcoin/rust-miniscript/"
@@ -63,4 +63,4 @@ required-features = ["compiler","std"]
6363

6464
[[example]]
6565
name = "psbt_sign_finalize"
66-
required-features = ["std"]
66+
required-features = ["std"]

src/policy/concrete.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,12 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk> {
657657
where
658658
Pk: 'a,
659659
{
660+
self.real_for_each_key(&mut pred)
661+
}
662+
}
663+
664+
impl<Pk: MiniscriptKey> Policy<Pk> {
665+
fn real_for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: &mut F) -> bool {
660666
match *self {
661667
Policy::Unsatisfiable | Policy::Trivial => true,
662668
Policy::Key(ref pk) => pred(pk),
@@ -667,14 +673,12 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk> {
667673
| Policy::After(..)
668674
| Policy::Older(..) => true,
669675
Policy::Threshold(_, ref subs) | Policy::And(ref subs) => {
670-
subs.iter().all(|sub| sub.for_each_key(&mut pred))
676+
subs.iter().all(|sub| sub.real_for_each_key(&mut *pred))
671677
}
672-
Policy::Or(ref subs) => subs.iter().all(|(_, sub)| sub.for_each_key(&mut pred)),
678+
Policy::Or(ref subs) => subs.iter().all(|(_, sub)| sub.real_for_each_key(&mut *pred)),
673679
}
674680
}
675-
}
676681

677-
impl<Pk: MiniscriptKey> Policy<Pk> {
678682
/// Convert a policy using one kind of public key to another
679683
/// type of public key
680684
///
@@ -1282,7 +1286,7 @@ fn generate_combination<Pk: MiniscriptKey>(
12821286
}
12831287

12841288
#[cfg(all(test, feature = "compiler"))]
1285-
mod tests {
1289+
mod compiler_tests {
12861290
use core::str::FromStr;
12871291

12881292
use sync::Arc;
@@ -1343,3 +1347,18 @@ mod tests {
13431347
assert_eq!(combinations, expected_comb);
13441348
}
13451349
}
1350+
1351+
#[cfg(test)]
1352+
mod tests {
1353+
use super::*;
1354+
use std::str::FromStr;
1355+
1356+
#[test]
1357+
fn for_each_key() {
1358+
let liquid_pol = Policy::<String>::from_str(
1359+
"or(and(older(4096),thresh(2,pk(A),pk(B),pk(C))),thresh(11,pk(F1),pk(F2),pk(F3),pk(F4),pk(F5),pk(F6),pk(F7),pk(F8),pk(F9),pk(F10),pk(F11),pk(F12),pk(F13),pk(F14)))").unwrap();
1360+
let mut count = 0;
1361+
assert!(liquid_pol.for_each_key(|_| { count +=1; true }));
1362+
assert_eq!(count, 17);
1363+
}
1364+
}

src/policy/semantic.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,25 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk> {
7676
where
7777
Pk: 'a,
7878
{
79+
self.real_for_each_key(&mut pred)
80+
}
81+
}
82+
83+
impl<Pk: MiniscriptKey> Policy<Pk> {
84+
fn real_for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: &mut F) -> bool {
7985
match *self {
8086
Policy::Unsatisfiable | Policy::Trivial => true,
81-
Policy::Key(ref _pkh) => todo!("Semantic Policy KeyHash must store Pk"),
87+
Policy::Key(ref pk) => pred(pk),
8288
Policy::Sha256(..)
8389
| Policy::Hash256(..)
8490
| Policy::Ripemd160(..)
8591
| Policy::Hash160(..)
8692
| Policy::After(..)
8793
| Policy::Older(..) => true,
88-
Policy::Threshold(_, ref subs) => subs.iter().all(|sub| sub.for_each_key(&mut pred)),
94+
Policy::Threshold(_, ref subs) => subs.iter().all(|sub| sub.real_for_each_key(&mut *pred)),
8995
}
9096
}
91-
}
9297

93-
impl<Pk: MiniscriptKey> Policy<Pk> {
9498
/// Convert a policy using one kind of public key to another
9599
/// type of public key
96100
///
@@ -994,4 +998,13 @@ mod tests {
994998
assert!(auth_alice.entails(htlc_pol.clone()).unwrap());
995999
assert!(htlc_pol.entails(control_alice).unwrap());
9961000
}
1001+
1002+
#[test]
1003+
fn for_each_key() {
1004+
let liquid_pol = StringPolicy::from_str(
1005+
"or(and(older(4096),thresh(2,pk(A),pk(B),pk(C))),thresh(11,pk(F1),pk(F2),pk(F3),pk(F4),pk(F5),pk(F6),pk(F7),pk(F8),pk(F9),pk(F10),pk(F11),pk(F12),pk(F13),pk(F14)))").unwrap();
1006+
let mut count = 0;
1007+
assert!(liquid_pol.for_each_key(|_| { count +=1; true }));
1008+
assert_eq!(count, 17);
1009+
}
9971010
}

0 commit comments

Comments
 (0)