Skip to main content

verified_anchor/
account.rs

1//! The six typed wrappers the M7a macro recognises. Each is a thin marker over
2//! `&'info AccountInfo<'info>`; `Account<'info, T>` additionally carries the
3//! Borsh-deserialised T (the macro fills it in `try_accounts`).
4
5use core::marker::PhantomData;
6use core::ops::{Deref, DerefMut};
7use solana_program::account_info::AccountInfo;
8
9use crate::account_data::{AccountData, ProgramId};
10
11/// `Account<'info, T>` — Anchor-style typed account. The macro auto-implies
12/// owner=crate::ID + discriminator=T::DISCRIMINATOR in validate, and
13/// Borsh-deserialises T in try_accounts (skipping the 8-byte discriminator).
14pub struct Account<'info, T: AccountData> {
15    pub info: &'info AccountInfo<'info>,
16    pub data: T,
17}
18
19impl<'info, T: AccountData> Deref for Account<'info, T> {
20    type Target = T;
21    fn deref(&self) -> &T { &self.data }
22}
23impl<'info, T: AccountData> DerefMut for Account<'info, T> {
24    fn deref_mut(&mut self) -> &mut T { &mut self.data }
25}
26
27/// `Signer<'info>` — auto-implies `is_signer == true`.
28pub struct Signer<'info> {
29    pub info: &'info AccountInfo<'info>,
30}
31
32/// `Program<'info, P>` — auto-implies `executable == true` AND `info.key == P::ID`.
33pub struct Program<'info, P: ProgramId> {
34    pub info: &'info AccountInfo<'info>,
35    _phantom: PhantomData<P>,
36}
37impl<'info, P: ProgramId> Program<'info, P> {
38    /// Constructed by the macro after the wrapper checks pass.
39    pub fn new(info: &'info AccountInfo<'info>) -> Self {
40        Self { info, _phantom: PhantomData }
41    }
42}
43
44/// `SystemAccount<'info>` — auto-implies `info.owner == system_program::ID`.
45pub struct SystemAccount<'info> {
46    pub info: &'info AccountInfo<'info>,
47}
48
49/// `UncheckedAccount<'info>` — escape hatch; no implied checks (explicit
50/// `#[account(...)]` attributes still apply).
51pub struct UncheckedAccount<'info> {
52    pub info: &'info AccountInfo<'info>,
53}
54
55// `AccountInfo<'info>` is the raw Solana type — re-exported from prelude as-is
56// (Task L3); no wrapper struct here.