Skip to main content

CachedClock

Struct CachedClock 

Source
pub struct CachedClock {
    pub slot: u64,
    pub epoch: u64,
    pub unix_timestamp: i64,
}
Expand description

Cached Clock sysvar fields.

Created once per instruction, used by multiple checks. Each field is Option – populated lazily on first access from account data.

Fields§

§slot: u64§epoch: u64§unix_timestamp: i64

Implementations§

Source§

impl CachedClock

Source

pub fn from_account_data(data: &[u8]) -> Result<Self, ProgramError>

Parse Clock sysvar from account data (40 bytes).

Call once at the start of your instruction, then pass the cached value to all checks that need clock data.

Source

pub fn check_not_expired(&self, deadline: i64) -> Result<(), ProgramError>

Check that a deadline has not passed.

Source

pub fn check_expired(&self, deadline: i64) -> Result<(), ProgramError>

Check that a deadline HAS passed (for claiming, unlocking, etc.).

Source

pub fn check_within_window( &self, start: i64, end: i64, ) -> Result<(), ProgramError>

Check that now is within a time window [start, end].

Source

pub fn check_cooldown( &self, last_action: i64, cooldown_secs: i64, ) -> Result<(), ProgramError>

Check cooldown: enough time has passed since last action.

Source

pub fn check_slot_staleness( &self, last_update_slot: u64, max_age: u64, ) -> Result<(), ProgramError>

Check slot staleness: last_update_slot is within max_age of current slot.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.