devol_accounts_kit/accounts/
devol_regular_account.rs

1use std::error::Error;
2use solana_program::account_info::{Account, AccountInfo, IntoAccountInfo};
3use solana_program::pubkey::Pubkey;
4use crate::accounts::devol_account::DevolAccount;
5use crate::dvl_error::DvlError;
6
7pub trait DevolRegularAccount: DevolAccount {
8    #[inline(always)]
9    fn check_all(account_info: &AccountInfo, root_addr: &Pubkey, program_id: &Pubkey) -> Result<(), DvlError> {
10        Self::check_basic(account_info, root_addr, program_id)
11    }
12
13    /// Transforms `AccountInfo` into a reference of `Self` for on-chain use without the intent to modify the data.
14    #[inline(always)]
15    fn from_account_info<'a>(
16        account_info: &'a AccountInfo,
17        root_addr: &Pubkey,
18        program_id: &Pubkey,
19    ) -> Result<&'a Self, DvlError>
20        where
21            Self: Sized,
22    {
23        Self::from_account_info_basic(account_info, root_addr, program_id)
24    }
25
26    /// Transforms `AccountInfo` into a mutable reference of `Self` for on-chain use with the intent to modify the data.
27    /// Ensures the account is marked as writable.
28    #[inline(always)]
29    fn from_account_info_mut<'a>(
30        account_info: &'a AccountInfo,
31        root_addr: &Pubkey,
32        program_id: &Pubkey,
33    ) -> Result<&'a mut Self, DvlError>
34        where
35            Self: Sized,
36    {
37        Self::from_account_info_mut_basic(account_info, root_addr, program_id)
38    }
39
40    /// Used off-chain to convert raw account data from RPC to a blockchain-utilized account structure.
41    #[inline(always)]
42    fn from_account(
43        key: &Pubkey,
44        account: &mut impl Account,
45        root_addr: &Pubkey,
46        program_id: &Pubkey,
47    ) -> Result<Box<Self>, Box<dyn Error>>
48        where
49            Self: Sized + Copy
50    {
51        let account_info = (key, account).into_account_info();
52        let account_ref = Self::from_account_info(&account_info, root_addr, program_id)?;
53        Ok(Box::new(*account_ref))
54    }
55}