Skip to content

Commit

Permalink
Remove BlockHeigth arithmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
Dentosal committed Oct 2, 2023
1 parent a139091 commit c9aff5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion fuel-tx/src/tests/valid_cases/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ fn mint() {
.add_output(Output::coin(rng.gen(), rng.next_u64(), AssetId::BASE))
.add_output(Output::coin(rng.gen(), rng.next_u64(), AssetId::BASE))
.finalize()
.check(block_height + 1.into(), &test_params())
.check(block_height.succ().unwrap(), &test_params())
.expect_err("Expected erroneous transaction");

assert_eq!(err, CheckError::TransactionMintIncorrectBlockHeight);
Expand Down
32 changes: 12 additions & 20 deletions fuel-types/src/numeric_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ use core::{
convert::TryFrom,
fmt,
ops::{
Add,
Deref,
DerefMut,
Sub,
},
str,
};
Expand Down Expand Up @@ -246,27 +244,21 @@ macro_rules! key_methods {
Ok(ret.into())
}
}

impl Add for $i {
type Output = $i;

#[inline(always)]
fn add(self, rhs: $i) -> $i {
$i(self.0.wrapping_add(rhs.0))
}
}

impl Sub for $i {
type Output = $i;

#[inline(always)]
fn sub(self, rhs: $i) -> $i {
$i(self.0.wrapping_sub(rhs.0))
}
}
};
};
}

key!(BlockHeight, u32);
key!(ChainId, u64);

impl BlockHeight {
/// Successor, i.e. next block after this
pub fn succ(self) -> Option<BlockHeight> {
Some(Self(self.0.checked_add(1)?))
}

/// Predecessor, i.e. previous block before this
pub fn pred(self) -> Option<BlockHeight> {
Some(Self(self.0.checked_sub(1)?))
}
}

0 comments on commit c9aff5a

Please sign in to comment.