use std::error::Error;
use solana_program::account_info::{Account, AccountInfo, IntoAccountInfo};
use solana_program::pubkey::Pubkey;
use crate::accounts::devol_account::DevolAccount;
use crate::dvl_error::DvlError;
pub trait DevolRegularAccount: DevolAccount {
#[inline(always)]
fn check_all(account_info: &AccountInfo, root_addr: &Pubkey, program_id: &Pubkey) -> Result<(), DvlError> {
Self::check_basic(account_info, root_addr, program_id)
}
#[inline(always)]
fn from_account_info<'a>(
account_info: &'a AccountInfo,
root_addr: &Pubkey,
program_id: &Pubkey,
) -> Result<&'a Self, DvlError>
where
Self: Sized,
{
Self::from_account_info_basic(account_info, root_addr, program_id)
}
#[inline(always)]
fn from_account_info_mut<'a>(
account_info: &'a AccountInfo,
root_addr: &Pubkey,
program_id: &Pubkey,
) -> Result<&'a mut Self, DvlError>
where
Self: Sized,
{
Self::from_account_info_mut_basic(account_info, root_addr, program_id)
}
#[inline(always)]
fn from_account(
key: &Pubkey,
account: &mut impl Account,
root_addr: &Pubkey,
program_id: &Pubkey,
) -> Result<Box<Self>, Box<dyn Error>>
where
Self: Sized + Copy
{
let account_info = (key, account).into_account_info();
let account_ref = Self::from_account_info(&account_info, root_addr, program_id)?;
Ok(Box::new(*account_ref))
}
}