1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use anchor_lang::prelude::*;
use hpl_utils::Default;

/// Enum representing different roles for the `AddressContainer` struct.
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub enum AddressContainerRole {
    /// Role for `AddressContainer` instances related to project mints.
    ProjectMints,
}

/// Account representing a container for storing addresses.
/// Addresses are associated with a particular role, specified by `AddressContainerRole`.
/// PDA: [ 'address_container', role, associated_with, index ]
/// Category: indexing_state
#[account]
#[derive(PartialEq, Eq, Debug)]
pub struct AddressContainer {
    /// Bump value used for PDA.
    pub bump: u8,

    /// Public key of the account associated with this address container.
    pub associated_with: Pubkey,

    /// Role of this address container, specifying its purpose (e.g., ProjectMints).
    pub role: AddressContainerRole,

    /// List of public keys (addresses) stored in this container.
    pub addresses: Vec<Pubkey>,
}

/// Default implementation for the `AddressContainer` struct.
/// It sets default values for each field when creating a new `AddressContainer` instance.
impl Default for AddressContainer {
    const LEN: usize = 64 + 8; // base size + 8 align

    /// Sets default values for each field of the `AddressContainer` struct.
    fn set_defaults(&mut self) {
        self.bump = 0;
        self.associated_with = Pubkey::default();
        self.role = AddressContainerRole::ProjectMints;
        self.addresses = vec![];
    }
}

/// Struct representing indexing information.
/// This will eventually help to refer to any indexed address with just 2 bytes.
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub struct Indexing {
    /// Number of address containers (address indexers) holding indexed addresses.
    pub containers: u8, // PDAs of Indexers

    /// The expected number of indexed addresses.
    pub expected: u64,

    /// The actual number of indexed addresses.
    pub indexed: u64,
}

/// Implementation for the `Indexing` struct.
impl Indexing {
    /// Length of the `Indexing` struct in bytes.
    pub const LEN: usize = 24;

    /// Creates a new `Indexing` instance with default values.
    pub fn default() -> Self {
        Self {
            containers: 0,
            expected: 0,
            indexed: 0,
        }
    }
}

/// Struct representing an indexed reference.
#[derive(AnchorSerialize, AnchorDeserialize, Clone, PartialEq, Debug, Default)]
pub struct IndexedReference {
    /// Index of the address container holding the indexed address.
    pub address_container_index: u8,

    /// Index of the address within the container.
    pub index_in_container: u8,
}