[policy] Remove the TooManyItemsSelected error

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.
This commit is contained in:
Alekos Filini 2021-02-13 10:58:26 -05:00
parent d0ffcdd009
commit fa2610538f
No known key found for this signature in database
GPG Key ID: 431401E4A4530061
2 changed files with 4 additions and 11 deletions

View 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]

View 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