# 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**](https://github.com/horuslabsio/TBA/blob/v3/src/components/lockable/lockable.cairo).

## Functions

### `_lock`

```rust
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`

```rust
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.<br>

**Returns**

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tbaexplorer.com/contracts/components/lockable.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
