From de5a6d3b41765713062cef732613e789bfbeb659 Mon Sep 17 00:00:00 2001 From: evalir Date: Wed, 2 Jul 2025 15:02:00 +0200 Subject: [PATCH] feat(calc): add current_timestamp utility fn No reason not to have this, useful for use also outside the calculator itself. --- src/utils/calc.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utils/calc.rs b/src/utils/calc.rs index 2cb280a..1c4dd49 100644 --- a/src/utils/calc.rs +++ b/src/utils/calc.rs @@ -95,12 +95,17 @@ impl SlotCalculator { /// The current slot number. pub fn current_slot(&self) -> u64 { - self.calculate_slot(chrono::Utc::now().timestamp() as u64) + self.calculate_slot(self.current_timestamp()) + } + + /// The current timestamp in seconds. + pub fn current_timestamp(&self) -> u64 { + chrono::Utc::now().timestamp() as u64 } /// The current number of seconds into the block window. pub fn current_timepoint_within_slot(&self) -> u64 { - self.calculate_timepoint_within_slot(chrono::Utc::now().timestamp() as u64) + self.calculate_timepoint_within_slot(self.current_timestamp()) } /// The timestamp of the first PoS block in the chain.