# Record Pointer System

### The Problem&#x20;

Scanning records, i.e finding tokens / unique tokens you own, is time consuming on Aleo because you have to try and decrypt every record in the blockchain to find which is yours.&#x20;

For context, Aleo is a sequence of blocks that are created over time that store data like encrypted records that hold the private balances of its users. So inside every block is a sequence of encrypted records.

### The Solution

To solve this one can actively scan Aleo for their newly created records and once they are found the owner can store pointers to the records they own. Like this you just scan once and then you know where your records are and can instantly reference them based on what you need.

<figure><img src="/files/D6YYMyCGoZBhyusWSax0" alt=""><figcaption></figcaption></figure>

### Record Pointer Data Model&#x20;

```
struct AvailRecord<N: Network> {
    pub pointer: Pointer<N>,
    pub metadata: Metadata,
}

struct Pointer<N: Network> {
    pub block_height: u32,
    pub transaction_id: N::TransactionID,
    pub transition_id: N::TransitionID,
    pub function_id: String,
    pub commitment: String,
    pub tag: String,
    pub spent: bool,
}

struct Metadata {
    pub record_type: RecordType,
    pub program_id: String,
}

enum RecordType {
    AleoCredits,
    NFT,
    Contracts,
    Tokens,
    None,
}
```

The `AvailRecord` data structure encapsulates the record pointer and metadata that is used to identify what type of record this references.\
\
The main components of a `Pointer` are the block height and the record commitment as this can be used to directly query the record on chain. The tag is used to identify if the record is spent or not and spent is used to keep track of that state.

### Storage

**Where do you store these record pointers ?**\
\
The record pointers are encrypted using your viewing key and are stored locally on your device in a database embedded inside your wallet. Like this you have easy access to the records you need, when you need them.&#x20;

**What happens if you lose access to your device or delete the app ?**

If you lose access to your wallet then you must go through recovery. Avail offers you the option to backup your encrypted record pointers so that when you recover you get instant access to your records again. If you opt out you will have to scan the whole Aleo blockchain again which can take quite some time to complete.


---

# 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://avail.gitbook.io/encrypted-record-pointers/record-pointer-system.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.
