solana_loader_v4_interface/
state.rs

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