spl_token_2022/extension/cpi_guard/
mod.rs1#[cfg(feature = "serde-traits")]
2use serde::{Deserialize, Serialize};
3use {
4 crate::{
5 extension::{BaseStateWithExtensions, Extension, ExtensionType, StateWithExtensionsMut},
6 state::Account,
7 },
8 bytemuck::{Pod, Zeroable},
9 solana_program::instruction::{get_stack_height, TRANSACTION_LEVEL_STACK_HEIGHT},
10 spl_pod::primitives::PodBool,
11};
12
13pub mod instruction;
15
16pub mod processor;
18
19#[repr(C)]
21#[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))]
22#[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))]
23#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
24pub struct CpiGuard {
25 pub lock_cpi: PodBool,
27}
28impl Extension for CpiGuard {
29 const TYPE: ExtensionType = ExtensionType::CpiGuard;
30}
31
32pub fn cpi_guard_enabled(account_state: &StateWithExtensionsMut<Account>) -> bool {
34 if let Ok(extension) = account_state.get_extension::<CpiGuard>() {
35 return extension.lock_cpi.into();
36 }
37 false
38}
39
40pub fn in_cpi() -> bool {
42 get_stack_height() > TRANSACTION_LEVEL_STACK_HEIGHT
43}