use {
super::{AccountState, Initializable},
crate::state::SizeOf,
bytemuck::{Pod, Zeroable},
pinocchio::pubkey::Pubkey,
shank::ShankAccount,
};
pub const AUTHORITY_OFFSET: usize = 0;
pub const PENDING_AUTHORITY_OFFSET: usize = 32;
pub const STATE_OFFSET: usize = 64;
#[repr(C)]
#[derive(ShankAccount, Copy, Clone, Pod, Zeroable)]
pub struct ProgramWhitelistAccount {
pub authority: Pubkey,
pub pending_authority: Pubkey, pub state: u8,
}
impl ProgramWhitelistAccount {
#[inline(always)]
pub fn pack(&self) -> [u8; Self::SIZE_OF] {
let bytes = bytemuck::bytes_of(self);
let mut array = [0u8; Self::SIZE_OF];
array.copy_from_slice(bytes);
array
}
#[inline(always)]
pub fn set_pending_authority(&mut self, new_pending_authority: &Pubkey) {
self.pending_authority = *new_pending_authority;
}
#[inline(always)]
pub fn clear_pending_authority(&mut self) {
self.pending_authority = Pubkey::default();
}
#[inline(always)]
pub fn pending_authority(&self) -> Option<&Pubkey> {
if self.pending_authority == Pubkey::default() {
None
} else {
Some(&self.pending_authority)
}
}
#[inline(always)]
pub fn set_initialized(&mut self) {
self.state = AccountState::Initialized as u8;
}
}
impl Initializable for ProgramWhitelistAccount {
#[inline(always)]
fn is_initialized(&self) -> bool {
self.state != AccountState::Uninitialized as u8
}
}