#![allow(non_snake_case)]
use crate::cfg_client;
use crate::prelude::*;
use std::cell::Ref;
#[repr(packed)]
#[zero_copy(unsafe)]
#[derive(Default, Debug)]
pub struct VrfPoolRow {
pub timestamp: i64,
pub pubkey: Pubkey,
}
#[repr(packed)]
#[account(zero_copy(unsafe))]
pub struct VrfPoolAccountData {
pub authority: Pubkey, pub queue: Pubkey,
pub escrow: Pubkey, pub min_interval: u32,
pub max_rows: u32,
pub size: u32,
pub idx: u32,
pub state_bump: u8,
pub _ebuf: [u8; 135], }
impl VrfPoolAccountData {
pub fn new<'info>(
vrf_pool_account_info: &'info AccountInfo,
) -> anchor_lang::Result<Ref<'info, VrfPoolAccountData>> {
let data = vrf_pool_account_info.try_borrow_data()?;
if data.len() < VrfPoolAccountData::discriminator().len() {
return Err(ErrorCode::AccountDiscriminatorNotFound.into());
}
let mut disc_bytes = [0u8; 8];
disc_bytes.copy_from_slice(&data[..8]);
if disc_bytes != VrfPoolAccountData::discriminator() {
return Err(ErrorCode::AccountDiscriminatorMismatch.into());
}
Ok(Ref::map(data, |data| {
bytemuck::from_bytes(&data[8..std::mem::size_of::<VrfPoolAccountData>() + 8])
}))
}
pub fn new_from_bytes(data: &[u8]) -> anchor_lang::Result<&VrfPoolAccountData> {
if data.len() < VrfPoolAccountData::discriminator().len() {
return Err(ErrorCode::AccountDiscriminatorNotFound.into());
}
let mut disc_bytes = [0u8; 8];
disc_bytes.copy_from_slice(&data[..8]);
if disc_bytes != VrfPoolAccountData::discriminator() {
return Err(ErrorCode::AccountDiscriminatorMismatch.into());
}
Ok(bytemuck::from_bytes(
&data[8..std::mem::size_of::<VrfPoolAccountData>() + 8],
))
}
cfg_client! {
pub fn fetch(
client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::SbError> {
crate::client::fetch_zerocopy_account(client, pubkey)
}
pub async fn fetch_async(
client: &solana_client::nonblocking::rpc_client::RpcClient,
pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::SbError> {
crate::client::fetch_zerocopy_account_async(client, pubkey).await
}
pub fn fetch_sync<T: solana_sdk::client::SyncClient>(
client: &T,
pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::SbError> {
crate::client::fetch_zerocopy_account_sync(client, pubkey)
}
}
}
impl Default for VrfPoolAccountData {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}