Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Daira-Emma Hopwood <[email protected]>
  • Loading branch information
nuttycom and daira authored Mar 6, 2024
1 parent 8955cfc commit f2f8af6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion components/zcash_protocol/src/constants/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub const HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY: &str = "zxviews";
/// [Zcash Protocol Specification]: https://github.com/zcash/zips/blob/master/protocol/protocol.pdf
pub const HRP_SAPLING_PAYMENT_ADDRESS: &str = "zs";

/// The prefix for a Base58Check-encoded mainnet Sprout address
/// The prefix for a Base58Check-encoded mainnet Sprout address.
///
/// Defined in the [Zcash Protocol Specification section 5.6.3][sproutpaymentaddrencoding].
///
Expand Down
2 changes: 1 addition & 1 deletion components/zcash_protocol/src/constants/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub const HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY: &str = "zxviewtestsapling";
/// [Zcash Protocol Specification]: https://github.com/zcash/zips/blob/master/protocol/protocol.pdf
pub const HRP_SAPLING_PAYMENT_ADDRESS: &str = "ztestsapling";

/// The prefix for a Base58Check-encoded testnet Sprout addresses.
/// The prefix for a Base58Check-encoded testnet Sprout address.
///
/// Defined in the [Zcash Protocol Specification section 5.6.3][sproutpaymentaddrencoding].
///
Expand Down
16 changes: 10 additions & 6 deletions components/zcash_protocol/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl TryFrom<ZatBalance> for u64 {
type Error = BalanceError;

fn try_from(value: ZatBalance) -> Result<Self, Self::Error> {
value.0.try_into().map_err(|_| BalanceError::Overflow)
value.0.try_into().map_err(|_| BalanceError::Underflow)

Check warning on line 158 in components/zcash_protocol/src/value.rs

View check run for this annotation

Codecov / codecov/patch

components/zcash_protocol/src/value.rs#L157-L158

Added lines #L157 - L158 were not covered by tests
}
}

Expand Down Expand Up @@ -261,11 +261,9 @@ impl Zatoshis {
///
/// Returns an error if the amount is outside the range `{0..MAX_MONEY}`.
pub fn from_nonnegative_i64(amount: i64) -> Result<Self, BalanceError> {
if amount >= 0 {
Self::from_u64(u64::try_from(amount).unwrap())
} else {
Err(BalanceError::Underflow)
}
u64::try_from(amount)
.map_err(|_| BalanceError::Underflow)
.and_then(Self::from_u64)
}

/// Reads an Zatoshis from an unsigned 64-bit little-endian integer.
Expand Down Expand Up @@ -439,6 +437,12 @@ pub mod testing {
}
}

prop_compose! {
pub fn arb_nonnegative_zat_balance()(amt in 0i64..MAX_BALANCE) -> ZatBalance {
ZatBalance::from_i64(amt).unwrap()

Check warning on line 442 in components/zcash_protocol/src/value.rs

View check run for this annotation

Codecov / codecov/patch

components/zcash_protocol/src/value.rs#L440-L442

Added lines #L440 - L442 were not covered by tests
}
}

prop_compose! {
pub fn arb_zatoshis()(amt in 0u64..MAX_MONEY) -> Zatoshis {
Zatoshis::from_u64(amt).unwrap()
Expand Down
2 changes: 1 addition & 1 deletion zcash_client_backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ and this library adheres to Rust's notion of
`NonNegativeAmount` rather than a signed `Amount`.

### Removed
- `zcash_client_backend::PoolType::is_receiver` use
- `zcash_client_backend::PoolType::is_receiver`: use
`zcash_keys::Address::has_receiver` instead.

## [0.11.0] - 2024-03-01
Expand Down
4 changes: 2 additions & 2 deletions zcash_client_backend/src/zip321.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ mod render {
format!("address{}={}", param_index(idx), addr.encode(params))
}

/// Converts an [`NonNegativeAmount`] value to a correctly formatted decimal ZEC
/// Converts a [`NonNegativeAmount`] value to a correctly formatted decimal ZEC string.
/// value for inclusion in a ZIP 321 URI.
pub fn amount_str(amount: NonNegativeAmount) -> Option<String> {
if amount.is_positive() {
Expand Down Expand Up @@ -671,7 +671,7 @@ mod parse {
.and_then(|coin_zats| coin_zats.checked_add(zats))
.ok_or(BalanceError::Overflow)
.and_then(NonNegativeAmount::from_u64)
.map_err(|_| format!("Not a valid zat amount: {}.{}", coins, zats))
.map_err(|_| format!("Not a valid amount: {}.{:0>8} ZEC", coins, zats))
},
)(input)
}
Expand Down

0 comments on commit f2f8af6

Please sign in to comment.