🔒Lockable

The Lockable component is designed to provide functionality for temporarily restricting actions on a token-bound account. It introduces a mechanism to "lock" an account for a defined period, during which only limited operations (if any) can be performed. This is particularly useful for scenarios where access control must be strictly enforced based on time conditions, e.g NFT marketplace purchases.

The full contract code of the LockableComponent can be found here.

Functions

_lock

fn _lock(ref self: ComponentState<TContractState>, lock_until: u64)

Locks the token-bound account until the specified timestamp ,lock_until.

Parameters

Name
Type
Description

lock_until

u64

A timestamp (in seconds) specifying when the contract will be unlocked. No further actions can be taken until this time has passed.

Additional Details

  1. Lock Time Validation: Before locking the account, the function checks whether the lock_until timestamp is within the allowed maximum lock period. The maximum duration is defined as one year (YEAR_TO_SECONDS = 31,536,000 seconds). If the provided lock time exceeds this limit, the function will throw an EXCEEDS_MAX_LOCK_TIME error.

  2. Lock Status Check: The function also verifies if the account is already locked by calling the internal _is_locked function. If the account is currently locked, it will raise a LOCKED_ACCOUNT error to prevent overwriting the lock.

_is_locked

fn is_locked(self: @TContractState) -> (bool, u64);

Checks the current lock status of the account. It determines whether the account is still within its locked period and, if so, calculates the remaining time until it will be unlocked.

Returns

(bool, u64): Lock status, and time until when the contract is unlocked.

Last updated