-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #660: Introduce Threshold type and use it in SortedMulti as a p…
…review 50bf404 policy: use new Threshold type in semantic policy (Andrew Poelstra) 5964ec3 sortedmulti: use new Threshold type internally (Andrew Poelstra) 36ea5cc expression: add method to validate and construct a threshold (Andrew Poelstra) 452615b rename expression.rs to expression/mod.rs (Andrew Poelstra) dbf7b32 primitives: introduce Threshold type (Andrew Poelstra) 30a3b59 psbt: fix "redundant target" doc warning (Andrew Poelstra) Pull request description: I have a big branch which uses this type throughout the codebase. I split it up into pieces (separate commit for its use in each policy type, for its use in multi/multi_a, for its use in Terminal::thresh, etc) but it's still a pretty big diff. Despite the size of the diff I think this is definitely worth doing -- in my current branch we have eliminated a ton of error paths, including a ton of badly-typed ones (grepping the codebase for `errstr` shows I've reduced it from 30 instances to 18). This PR simply introduces the new `Threshold` type and uses it in `SortedMultiVec` to show how the API works. Later PRs will do the more invasive stuff. ACKs for top commit: tcharding: ACK 50bf404 sanket1729: ACK 50bf404. Tree-SHA512: 084034f43a66cb6e73446549aad1e1a01f7f0067e7ab3b401f8d819f7375f7a0f6b695c013e3917f550d07b579dcd8ca21adf6dd854bb82c824911e8d1ead152
- Loading branch information
Showing
10 changed files
with
623 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: CC0-1.0 | ||
|
||
//! Expression-related errors | ||
|
||
use core::fmt; | ||
|
||
use crate::prelude::*; | ||
use crate::ThresholdError; | ||
|
||
/// Error parsing a threshold expression. | ||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
pub enum ParseThresholdError { | ||
/// Expression had no children, not even a threshold value. | ||
NoChildren, | ||
/// The threshold value appeared to be a sub-expression rather than a number. | ||
KNotTerminal, | ||
/// Failed to parse the threshold value. | ||
// FIXME this should be a more specific type. Will be handled in a later PR | ||
// that rewrites the expression parsing logic. | ||
ParseK(String), | ||
/// Threshold parameters were invalid. | ||
Threshold(ThresholdError), | ||
} | ||
|
||
impl fmt::Display for ParseThresholdError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
use ParseThresholdError::*; | ||
|
||
match *self { | ||
NoChildren => f.write_str("expected threshold, found terminal"), | ||
KNotTerminal => f.write_str("expected positive integer, found expression"), | ||
ParseK(ref x) => write!(f, "failed to parse threshold value {}", x), | ||
Threshold(ref e) => e.fmt(f), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
impl std::error::Error for ParseThresholdError { | ||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { | ||
use ParseThresholdError::*; | ||
|
||
match *self { | ||
NoChildren => None, | ||
KNotTerminal => None, | ||
ParseK(..) => None, | ||
Threshold(ref e) => Some(e), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.