Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,7 @@ mod tests {
#[test]
fn tr_roundtrip_key() {
let script = Tr::<String>::from_str("tr()").unwrap().to_string();
assert_eq!(script, format!("tr()#x4ml3kxd"))
assert_eq!(script, "tr()#x4ml3kxd".to_string())
}

#[test]
Expand Down
12 changes: 10 additions & 2 deletions src/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ pub use self::error::{ParseNumError, ParseThresholdError, ParseTreeError};
use crate::blanket_traits::StaticDebugAndDisplay;
use crate::descriptor::checksum::verify_checksum;
use crate::prelude::*;
use crate::{AbsLockTime, Error, ParseError, RelLockTime, Threshold, MAX_RECURSION_DEPTH};
use crate::{
AbsLockTime, Error, ParseError, PositiveF64, RelLockTime, Threshold, MAX_RECURSION_DEPTH,
};

/// Allowed characters are descriptor strings.
pub const INPUT_CHARSET: &str = "0123456789()[],'/*abcdefgh@:$%{}IJKLMNOPQRSTUVWXYZ&+-.;<=>?!^_|~ijklmnopqrstuvwxyzABCDEFGH`#\"\\ ";
Expand Down Expand Up @@ -679,7 +681,7 @@ impl<'a> Tree<'a> {
}

/// Parse a string as a u32, forbidding zero.
pub fn parse_num_nonzero(s: &str, context: &'static str) -> Result<u32, ParseNumError> {
fn parse_num_nonzero(s: &str, context: &'static str) -> Result<u32, ParseNumError> {
if s == "0" {
return Err(ParseNumError::IllegalZero { context });
}
Expand All @@ -691,6 +693,12 @@ pub fn parse_num_nonzero(s: &str, context: &'static str) -> Result<u32, ParseNum
u32::from_str(s).map_err(ParseNumError::StdParse)
}

/// Parse a string as a PositiveF64, forbidding zero.
pub fn parse_probability(s: &str, context: &'static str) -> Result<PositiveF64, ParseNumError> {
let parsed = parse_num_nonzero(s, context)?;
PositiveF64::try_from(parsed).map_err(|_| ParseNumError::IllegalZero { context })
}

/// Parse a string as a u32, for timelocks or thresholds
pub fn parse_num(s: &str) -> Result<u32, ParseNumError> {
if s == "0" {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub use crate::miniscript::satisfy::{Preimage32, Satisfier};
pub use crate::miniscript::{hash256, Miniscript};
use crate::prelude::*;
pub use crate::primitives::absolute_locktime::{AbsLockTime, AbsLockTimeError};
pub use crate::primitives::positive_f64::PositiveF64;
pub use crate::primitives::relative_locktime::{RelLockTime, RelLockTimeError};
pub use crate::primitives::threshold::{Threshold, ThresholdError};
pub use crate::validation::{Error as ValidationError, ValidationParams};
Expand Down
Loading