pub struct SlotCalculator { /* private fields */ }Expand description
A slot calculator, which can calculate the slot number for a given timestamp.
Implementations§
Source§impl SlotCalculator
impl SlotCalculator
Sourcepub const fn new(
start_timestamp: u64,
slot_offset: u64,
slot_duration: u64,
) -> Self
pub const fn new( start_timestamp: u64, slot_offset: u64, slot_duration: u64, ) -> Self
Creates a new slot calculator.
Sourcepub const fn calculate_slot(&self, timestamp: u64) -> u64
pub const fn calculate_slot(&self, timestamp: u64) -> u64
Calculates the slot for a given timestamp. This only works for timestamps that are GEQ to the chain’s start_timestamp.
Sourcepub const fn calculate_timepoint_within_slot(&self, timestamp: u64) -> u64
pub const fn calculate_timepoint_within_slot(&self, timestamp: u64) -> u64
Calculates how many seconds into the block window for a given timestamp.
Sourcepub const fn calculate_slot_window(&self, slot_number: u64) -> (u64, u64)
pub const fn calculate_slot_window(&self, slot_number: u64) -> (u64, u64)
Calculates the start and end timestamps for a given slot
Sourcepub fn current_slot(&self) -> u64
pub fn current_slot(&self) -> u64
The current slot number.
Sourcepub fn current_timepoint_within_slot(&self) -> u64
pub fn current_timepoint_within_slot(&self) -> u64
The current number of seconds into the block window.
Sourcepub const fn start_timestamp(&self) -> u64
pub const fn start_timestamp(&self) -> u64
The timestamp of the first PoS block in the chain.
Sourcepub const fn slot_offset(&self) -> u64
pub const fn slot_offset(&self) -> u64
The slot number of the first PoS block in the chain.
Sourcepub const fn slot_duration(&self) -> u64
pub const fn slot_duration(&self) -> u64
The slot duration, usually 12 seconds.
Trait Implementations§
Source§impl Clone for SlotCalculator
impl Clone for SlotCalculator
Source§fn clone(&self) -> SlotCalculator
fn clone(&self) -> SlotCalculator
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SlotCalculator
impl Debug for SlotCalculator
Source§impl FromEnv for SlotCalculator
impl FromEnv for SlotCalculator
Source§type Error = SlotCalcEnvError
type Error = SlotCalcEnvError
Error type produced when loading from the environment.
Source§fn inventory() -> Vec<&'static EnvItemInfo>
fn inventory() -> Vec<&'static EnvItemInfo>
Get the required environment variable names for this type. Read more
Source§fn check_inventory() -> Result<(), Vec<&'static EnvItemInfo>>
fn check_inventory() -> Result<(), Vec<&'static EnvItemInfo>>
Get a list of missing environment variables. Read more
Source§impl PartialEq for SlotCalculator
impl PartialEq for SlotCalculator
impl Copy for SlotCalculator
impl Eq for SlotCalculator
impl StructuralPartialEq for SlotCalculator
Auto Trait Implementations§
impl Freeze for SlotCalculator
impl RefUnwindSafe for SlotCalculator
impl Send for SlotCalculator
impl Sync for SlotCalculator
impl Unpin for SlotCalculator
impl UnwindSafe for SlotCalculator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.