]> Untitled Git - bdk/commitdiff
[policy] Remove the `TooManyItemsSelected` error
authorAlekos Filini <alekos.filini@gmail.com>
Sat, 13 Feb 2021 15:58:26 +0000 (10:58 -0500)
committerAlekos Filini <alekos.filini@gmail.com>
Sat, 13 Feb 2021 16:10:31 +0000 (11:10 -0500)
The `TooManyItemsSelected` error has been removed, since it's not technically an
error but potentailly more of an "over-constraint" over a tx: for instance,
given a `thresh(3,pk(a),pk(b),older(10),older(20))` descriptor one could create
a spending tx with the `[0,1,2]` items that would only be spendable after `10`
blocks, or a tx with the `[0,2,3]` items that would be spendable after `20`.

In this case specifying more items than the threshold would create a tx with
the maximum constraint possible, in this case the `20` blocks. This is not
necessarily an error, so we should allow it without failing.

CHANGELOG.md
src/descriptor/policy.rs

index 0b958d62637b115c297edad3ab9c12a48edb5e0c..b683d1cff5c638a39d6a57b92eeddda41586c754 100644 (file)
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Policy
 #### Changed
 - Removed unneeded `Result<(), PolicyError>` return type for `Satisfaction::finalize()`
+- Removed the `TooManyItemsSelected` policy error (see commit message for more details)
 
 ## [v0.3.0] - [v0.2.0]
 
index 54ba808bd1da801924b52bcb74c2c4c4def40a6d..40d8efb3bda70b41d1905b5a26c95eaa3531af94 100644 (file)
@@ -47,7 +47,7 @@
 //! # Ok::<(), bdk::Error>(())
 //! ```
 
-use std::cmp::{max, Ordering};
+use std::cmp::max;
 use std::collections::{BTreeMap, HashSet, VecDeque};
 use std::fmt;
 
@@ -510,8 +510,6 @@ impl Condition {
 pub enum PolicyError {
     /// Not enough items are selected to satisfy a [`SatisfiableItem::Thresh`]
     NotEnoughItemsSelected(String),
-    /// Too many items are selected to satisfy a [`SatisfiableItem::Thresh`]
-    TooManyItemsSelected(String),
     /// Index out of range for an item to satisfy a [`SatisfiableItem::Thresh`]
     IndexOutOfRange(usize),
     /// Can not add to an item that is [`Satisfaction::None`] or [`Satisfaction::Complete`]
@@ -668,14 +666,8 @@ impl Policy {
                 // if we have something, make sure we have enough items. note that the user can set
                 // an empty value for this step in case of n-of-n, because `selected` is set to all
                 // the elements above
-                match selected.len().cmp(threshold) {
-                    Ordering::Less => {
-                        return Err(PolicyError::NotEnoughItemsSelected(self.id.clone()))
-                    }
-                    Ordering::Greater => {
-                        return Err(PolicyError::TooManyItemsSelected(self.id.clone()))
-                    }
-                    Ordering::Equal => (),
+                if selected.len() < *threshold {
+                    return Err(PolicyError::NotEnoughItemsSelected(self.id.clone()));
                 }
 
                 // check the selected items, see if there are conflicting requirements