Fix incorrect zip321 amount parsing.
This commit is contained in:
parent
6b4942f8eb
commit
376db4684b
|
@ -64,6 +64,11 @@ and this library adheres to Rust's notion of
|
||||||
- `zcash_client_backend::PoolType::is_receiver`: use
|
- `zcash_client_backend::PoolType::is_receiver`: use
|
||||||
`zcash_keys::Address::has_receiver` instead.
|
`zcash_keys::Address::has_receiver` instead.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- This release fixes an error in amount parsing in `zip321` that previously
|
||||||
|
allowed amounts having a decimal point but no decimal value to be parsed
|
||||||
|
as valid.
|
||||||
|
|
||||||
## [0.11.0] - 2024-03-01
|
## [0.11.0] - 2024-03-01
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -458,7 +458,7 @@ mod parse {
|
||||||
use nom::{
|
use nom::{
|
||||||
bytes::complete::{tag, take_till},
|
bytes::complete::{tag, take_till},
|
||||||
character::complete::{alpha1, char, digit0, digit1, one_of},
|
character::complete::{alpha1, char, digit0, digit1, one_of},
|
||||||
combinator::{map_opt, map_res, opt, recognize},
|
combinator::{all_consuming, map_opt, map_res, opt, recognize},
|
||||||
sequence::{preceded, separated_pair, tuple},
|
sequence::{preceded, separated_pair, tuple},
|
||||||
AsChar, IResult, InputTakeAtPosition,
|
AsChar, IResult, InputTakeAtPosition,
|
||||||
};
|
};
|
||||||
|
@ -642,13 +642,13 @@ mod parse {
|
||||||
/// Parses a value in decimal ZEC.
|
/// Parses a value in decimal ZEC.
|
||||||
pub fn parse_amount(input: &str) -> IResult<&str, NonNegativeAmount> {
|
pub fn parse_amount(input: &str) -> IResult<&str, NonNegativeAmount> {
|
||||||
map_res(
|
map_res(
|
||||||
tuple((
|
all_consuming(tuple((
|
||||||
digit1,
|
digit1,
|
||||||
opt(preceded(
|
opt(preceded(
|
||||||
char('.'),
|
char('.'),
|
||||||
map_opt(digit1, |s: &str| if s.len() > 8 { None } else { Some(s) }),
|
map_opt(digit1, |s: &str| if s.len() > 8 { None } else { Some(s) }),
|
||||||
)),
|
)),
|
||||||
)),
|
))),
|
||||||
|(whole_s, decimal_s): (&str, Option<&str>)| {
|
|(whole_s, decimal_s): (&str, Option<&str>)| {
|
||||||
let coins: u64 = whole_s
|
let coins: u64 = whole_s
|
||||||
.to_string()
|
.to_string()
|
||||||
|
@ -667,7 +667,7 @@ mod parse {
|
||||||
.and_then(|coin_zats| coin_zats.checked_add(zats))
|
.and_then(|coin_zats| coin_zats.checked_add(zats))
|
||||||
.ok_or(BalanceError::Overflow)
|
.ok_or(BalanceError::Overflow)
|
||||||
.and_then(NonNegativeAmount::from_u64)
|
.and_then(NonNegativeAmount::from_u64)
|
||||||
.map_err(|_| format!("Not a valid amount: {}.{:0>8} ZEC", coins, zats))
|
.map_err(|_| format!("Not a valid amount: {} ZEC", input))
|
||||||
},
|
},
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue