I am trying to obtain the state of a token account(spl_token::state::Account::AccountState
), How do I deserialize a raw Solana Account to obtain this state. Other solutions i have come across involve using AccountInfo
but I want to achieve this with rust without using anchor
1 Answer
AccountInfo
is not an Anchor type, but rather a solana-program
type. So if you want to get the state, you can deserialize from a given AccountInfo
using:
solana_program::entrypoint!(process_instruction);
pub fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
_instruction_data: &[u8],
) -> ProgramResult {
// Create an iterator to safely reference accounts in the slice
let account_info_iter = &mut accounts.iter();
let token_account_info = next_account_info(account_info_iter)?;
let token_account = Account::unpack(&token_account_info.try_borrow_data()?)?;
let state = token_account.state;
}