clone_solana_loader_v4_interface/
state.rs

1use clone_solana_pubkey::Pubkey;
2
3#[repr(u64)]
4#[cfg_attr(
5    feature = "frozen-abi",
6    derive(clone_solana_frozen_abi_macro::AbiExample)
7)]
8#[derive(Debug, PartialEq, Eq, Clone, Copy)]
9pub enum LoaderV4Status {
10    /// Program is in maintenance
11    Retracted,
12    /// Program is ready to be executed
13    Deployed,
14    /// Same as `Deployed`, but can not be retracted anymore
15    Finalized,
16}
17
18/// LoaderV4 account states
19#[repr(C)]
20#[cfg_attr(
21    feature = "frozen-abi",
22    derive(clone_solana_frozen_abi_macro::AbiExample)
23)]
24#[derive(Debug, PartialEq, Eq, Clone, Copy)]
25pub struct LoaderV4State {
26    /// Slot in which the program was last deployed, retracted or initialized.
27    pub slot: u64,
28    /// Address of signer which can send program management instructions when the status is not finalized.
29    /// Otherwise a forwarding to the next version of the finalized program.
30    pub authority_address_or_next_version: Pubkey,
31    /// Deployment status.
32    pub status: LoaderV4Status,
33    // The raw program data follows this serialized structure in the
34    // account's data.
35}
36
37impl LoaderV4State {
38    /// Size of a serialized program account.
39    pub const fn program_data_offset() -> usize {
40        std::mem::size_of::<Self>()
41    }
42}
43
44#[cfg(test)]
45mod tests {
46    use {super::*, memoffset::offset_of};
47
48    #[test]
49    fn test_layout() {
50        assert_eq!(offset_of!(LoaderV4State, slot), 0x00);
51        assert_eq!(
52            offset_of!(LoaderV4State, authority_address_or_next_version),
53            0x08
54        );
55        assert_eq!(offset_of!(LoaderV4State, status), 0x28);
56        assert_eq!(LoaderV4State::program_data_offset(), 0x30);
57    }
58}