Skip to content

Commit

Permalink
fixup! Merge branch 'tomas/checked-arith' (#3074)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed May 8, 2024
1 parent a6f15dd commit 3b048d4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
9 changes: 0 additions & 9 deletions crates/core/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,15 +1015,6 @@ pub mod testing {
}
}

impl std::ops::Mul<Uint> for Amount {
type Output = Amount;

fn mul(mut self, rhs: Uint) -> Self::Output {
self.raw *= rhs;
self
}
}

impl std::ops::Div<u64> for Amount {
type Output = Self;

Expand Down
15 changes: 11 additions & 4 deletions crates/core/src/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,13 @@ impl FromStr for I256 {

fn from_str(num: &str) -> Result<Self, Self::Err> {
if let Some(("", neg_num)) = num.split_once('-') {
let uint = neg_num.parse::<Uint>()?.negate();
let (uint, overflow) = neg_num.parse::<Uint>()?.negate();
if overflow {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::InvalidData,
"I256 overflow",
)));
}
Ok(I256(uint))
} else {
let uint = num.parse::<Uint>()?;
Expand All @@ -522,8 +528,9 @@ impl FromStr for I256 {

impl I256 {
/// Compute the two's complement of a number.
pub fn negate(&self) -> Self {
Self(self.0.negate())
pub fn negate(&self) -> Option<Self> {
let (uint, overflow) = self.0.negate();
if overflow { None } else { Some(Self(uint)) }
}

/// Check if the amount is not negative (greater
Expand Down Expand Up @@ -1133,7 +1140,7 @@ mod test_uint {

#[test]
fn test_i256_str_roundtrip() {
let minus_one = I256::one().negate();
let minus_one = I256::one().negate().unwrap();
let minus_one_str = minus_one.to_string();
assert_eq!(minus_one_str, "-1");

Expand Down
2 changes: 1 addition & 1 deletion crates/namada/src/ledger/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ where
.map_err(|e| Error::FeeError(e.to_string()))?;

let current_block_height =
state.in_mem().get_last_block_height() + 1;
state.in_mem().get_last_block_height().next_height();

if let Some(post_bal) = balance.checked_sub(fees) {
token_transfer(
Expand Down
1 change: 0 additions & 1 deletion crates/sdk/src/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ use masp_proofs::prover::LocalTxProver;
#[cfg(not(feature = "testing"))]
use masp_proofs::sapling::SaplingVerificationContext;
use namada_core::address::Address;
use namada_core::arith::checked;
use namada_core::collections::{HashMap, HashSet};
use namada_core::dec::Dec;
pub use namada_core::masp::{
Expand Down

0 comments on commit 3b048d4

Please sign in to comment.