Skip to content

Commit

Permalink
feat(Timestamp): implement AddAssign
Browse files Browse the repository at this point in the history
Closes #221 .
  • Loading branch information
cyberbono3 authored Nov 4, 2024
1 parent 3132267 commit 640b960
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/models/blockchain/block/difficulty_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ mod test {
);
block_times.push(block_time);
let old_timestamp = new_timestamp;
new_timestamp = new_timestamp + Timestamp::seconds(block_time.round() as u64);
new_timestamp += Timestamp::seconds(block_time.round() as u64);

difficulty = difficulty_control(
new_timestamp,
Expand Down
2 changes: 1 addition & 1 deletion src/models/blockchain/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ mod block_tests {

for i in (0..30).step_by(1) {
let duration = i as u64 * multiplier;
now = now + Timestamp::millis(duration);
now += Timestamp::millis(duration);

let (block, _, _) =
make_mock_block(&block_prev, Some(now), a_recipient_address, rng.gen());
Expand Down
4 changes: 2 additions & 2 deletions src/models/blockchain/transaction/validity/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ pub(crate) mod test {
.await
.unwrap();
let num_seconds = (0u64..=10).new_tree(&mut test_runner).unwrap().current();
updated.kernel.timestamp = updated.kernel.timestamp + Timestamp::seconds(num_seconds);
updated.kernel.timestamp += Timestamp::seconds(num_seconds);

UpdateWitness::from_old_transaction(
old_pw.kernel,
Expand Down Expand Up @@ -820,7 +820,7 @@ pub(crate) mod test {
let mut new_kernel = primitive_witness.kernel.clone();
new_kernel.mutator_set_hash = new_msa.hash();

new_kernel.timestamp = new_kernel.timestamp + Timestamp::days(1);
new_kernel.timestamp += Timestamp::days(1);
assert_ne!(
new_msa, primitive_witness.mutator_set_accumulator,
"must update mutator set too in order for test to be meaningful"
Expand Down
7 changes: 7 additions & 0 deletions src/models/proof_abstractions/timestamp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::fmt::Display;
use std::ops::Add;
use std::ops::AddAssign;
use std::ops::Mul;
use std::ops::Sub;
use std::time::SystemTime;
Expand Down Expand Up @@ -79,6 +80,12 @@ impl Sub for Timestamp {
}
}

impl AddAssign for Timestamp {
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs
}
}

impl Mul<usize> for Timestamp {
type Output = Timestamp;

Expand Down

0 comments on commit 640b960

Please sign in to comment.