pub struct InterfaceTokenAccount<'a> {
pub kind: TokenProgramKind,
/* private fields */
}Expand description
Polymorphic SPL Token / Token-2022 token-account overlay.
Construct via InterfaceTokenAccount::from_data using a borrowed
view of an account body that has already been ownership-checked
via TokenProgramKind::for_account. The constructor validates
the body is at least crate::token::TOKEN_ACCOUNT_LEN (165) bytes.
The reader methods delegate to crate::token, which is correct
for both programs because the first 165 bytes of a Token-2022
account match the SPL Token layout exactly.
let kind = TokenProgramKind::for_account(&view)?;
let data = view.try_borrow()?;
let token = InterfaceTokenAccount::from_data(&data, kind)?;
let mint = token.mint()?;Fields§
§kind: TokenProgramKindWhich program owns the account.
Implementations§
Source§impl<'a> InterfaceTokenAccount<'a>
impl<'a> InterfaceTokenAccount<'a>
Sourcepub fn from_data(
data: &'a [u8],
kind: TokenProgramKind,
) -> Result<InterfaceTokenAccount<'a>, ProgramError>
pub fn from_data( data: &'a [u8], kind: TokenProgramKind, ) -> Result<InterfaceTokenAccount<'a>, ProgramError>
Wrap a previously-borrowed account body.
Caller is responsible for confirming kind matches the
account’s actual owner - usually by calling
TokenProgramKind::for_account beforehand.
Sourcepub fn mint(&self) -> Result<&'a Address, ProgramError>
pub fn mint(&self) -> Result<&'a Address, ProgramError>
The mint pubkey.
Sourcepub fn owner(&self) -> Result<&'a Address, ProgramError>
pub fn owner(&self) -> Result<&'a Address, ProgramError>
The owner pubkey of the token account (the user wallet, not the program owning the account).
Sourcepub fn amount(&self) -> Result<u64, ProgramError>
pub fn amount(&self) -> Result<u64, ProgramError>
The token amount.
Sourcepub fn state(&self) -> Result<u8, ProgramError>
pub fn state(&self) -> Result<u8, ProgramError>
The state byte (0 = uninitialised, 1 = initialised, 2 = frozen).
Sourcepub fn assert_initialized(&self) -> Result<(), ProgramError>
pub fn assert_initialized(&self) -> Result<(), ProgramError>
Convenience: assert the account is initialised.
Sourcepub fn assert_owner(&self, expected: &Address) -> Result<(), ProgramError>
pub fn assert_owner(&self, expected: &Address) -> Result<(), ProgramError>
Convenience: assert the wallet owner matches.
Sourcepub fn assert_mint(&self, expected: &Address) -> Result<(), ProgramError>
pub fn assert_mint(&self, expected: &Address) -> Result<(), ProgramError>
Convenience: assert the mint matches.
Trait Implementations§
Source§impl<'a> Clone for InterfaceTokenAccount<'a>
impl<'a> Clone for InterfaceTokenAccount<'a>
Source§fn clone(&self) -> InterfaceTokenAccount<'a>
fn clone(&self) -> InterfaceTokenAccount<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more