wasm_multisig/
time_lock.rs

1use std::time::SystemTime;
2
3/// A struct that represents a time-based lock mechanism, which tracks an expiration time
4/// and provides functionality to check if the lock has expired.
5pub struct TimeLock {
6    pub expiry: SystemTime,   // The point in time when the lock will expire
7    pub expired: bool,        // A boolean flag indicating whether the lock has expired
8}
9
10impl TimeLock {
11    /// Checks if the TimeLock has expired by comparing the current system time with the expiration time.
12    /// Once the lock has expired, it will set the `expired` flag to `true` and return the result.
13    ///
14    /// # Returns
15    /// * `true` if the lock has expired, `false` otherwise.
16    pub fn is_expired(&mut self) -> bool {
17        // If the lock has not expired yet and the current time is past the expiry time, mark it as expired
18        if !self.expired && SystemTime::now() >= self.expiry {
19            self.expired = true;
20        }
21        self.expired
22    }
23}