safe_token_2022/extension/cpi_guard/
mod.rs1use {
2 crate::{
3 extension::{BaseStateWithExtensions, Extension, ExtensionType, StateWithExtensionsMut},
4 pod::PodBool,
5 state::Account,
6 },
7 bytemuck::{Pod, Zeroable},
8 solana_program::instruction::{get_stack_height, TRANSACTION_LEVEL_STACK_HEIGHT},
9};
10
11pub mod instruction;
13
14pub mod processor;
16
17#[repr(C)]
19#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
20pub struct CpiGuard {
21 pub lock_cpi: PodBool,
23}
24impl Extension for CpiGuard {
25 const TYPE: ExtensionType = ExtensionType::CpiGuard;
26}
27
28pub fn cpi_guard_enabled(account_state: &StateWithExtensionsMut<Account>) -> bool {
30 if let Ok(extension) = account_state.get_extension::<CpiGuard>() {
31 return extension.lock_cpi.into();
32 }
33 false
34}
35
36pub fn in_cpi() -> bool {
38 get_stack_height() > TRANSACTION_LEVEL_STACK_HEIGHT
39}