Skip to content

Commit ee15056

Browse files
committed
policy: remove now-unused semantic::PolicyError type
All semantic errors were actually parsing errors (except for the entailment failure mode, which was better represented as an option). Now that we are strongly-typing parsing errors we do not need this enum.
1 parent ce3d3e8 commit ee15056

File tree

1 file changed

+10
-35
lines changed

1 file changed

+10
-35
lines changed

src/policy/semantic.rs

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//! "abstract" is a reserved keyword in Rust.
77
88
use core::{fmt, str};
9-
#[cfg(feature = "std")]
10-
use std::error;
119

1210
use bitcoin::{absolute, relative};
1311

@@ -50,32 +48,6 @@ pub enum Policy<Pk: MiniscriptKey> {
5048
Thresh(Threshold<Arc<Policy<Pk>>, 0>),
5149
}
5250

53-
/// Detailed error type for concrete policies.
54-
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
55-
pub enum PolicyError {
56-
/// Entailment max terminals exceeded.
57-
EntailmentMaxTerminals,
58-
}
59-
60-
impl fmt::Display for PolicyError {
61-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
62-
match *self {
63-
PolicyError::EntailmentMaxTerminals => {
64-
write!(f, "Policy entailment only supports {} terminals", ENTAILMENT_MAX_TERMINALS)
65-
}
66-
}
67-
}
68-
}
69-
70-
#[cfg(feature = "std")]
71-
impl error::Error for PolicyError {
72-
fn cause(&self) -> Option<&dyn error::Error> {
73-
match self {
74-
PolicyError::EntailmentMaxTerminals => None,
75-
}
76-
}
77-
}
78-
7951
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk> {
8052
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool {
8153
self.pre_order_iter().all(|policy| match policy {
@@ -164,17 +136,20 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
164136
///
165137
/// This implementation will run slowly for larger policies but should be
166138
/// sufficient for most practical policies.
139+
///
140+
/// Returns None for very large policies for which entailment cannot
141+
/// be practically computed.
167142
// This algorithm has a naive implementation. It is possible to optimize this
168143
// by memoizing and maintaining a hashmap.
169-
pub fn entails(self, other: Policy<Pk>) -> Result<bool, PolicyError> {
144+
pub fn entails(self, other: Policy<Pk>) -> Option<bool> {
170145
if self.n_terminals() > ENTAILMENT_MAX_TERMINALS {
171-
return Err(PolicyError::EntailmentMaxTerminals);
146+
return None;
172147
}
173148
match (self, other) {
174-
(Policy::Unsatisfiable, _) => Ok(true),
175-
(Policy::Trivial, Policy::Trivial) => Ok(true),
176-
(Policy::Trivial, _) => Ok(false),
177-
(_, Policy::Unsatisfiable) => Ok(false),
149+
(Policy::Unsatisfiable, _) => Some(true),
150+
(Policy::Trivial, Policy::Trivial) => Some(true),
151+
(Policy::Trivial, _) => Some(false),
152+
(_, Policy::Unsatisfiable) => Some(false),
178153
(a, b) => {
179154
let (a_norm, b_norm) = (a.normalized(), b.normalized());
180155
let first_constraint = a_norm.first_constraint();
@@ -186,7 +161,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
186161
a_norm.satisfy_constraint(&first_constraint, false),
187162
b_norm.satisfy_constraint(&first_constraint, false),
188163
);
189-
Ok(Policy::entails(a1, b1)? && Policy::entails(a2, b2)?)
164+
Some(Policy::entails(a1, b1)? && Policy::entails(a2, b2)?)
190165
}
191166
}
192167
}

0 commit comments

Comments
 (0)