star_frame 0.29.0

A high performance Solana framework for building fast, scalable, and secure smart contracts.
Documentation
//! A single account that is owned by the system program.
use derive_more::{Deref, DerefMut};
use star_frame::prelude::*;

use crate::account_set::HasOwnerProgram;

/// A single account that is owned by the system program.
#[derive(AccountSet, Debug, Deref, DerefMut, Clone, Copy)]
#[validate(extra_validation = self.check_id())]
#[repr(transparent)]
pub struct SystemAccount(#[single_account_set(skip_has_owner_program)] AccountInfo);

impl SystemAccount {
    #[inline]
    pub fn check_id(&self) -> Result<()> {
        if self.owner().fast_eq(&System::ID) {
            Ok(())
        } else {
            Err(ProgramError::IllegalOwner.into())
        }
    }
}

impl HasOwnerProgram for SystemAccount {
    type OwnerProgram = System;
}