light_token_interface/instructions/transfer2/
cpi_context.rs

1use light_compressed_account::instruction_data::zero_copy_set::CompressedCpiContextTrait;
2use light_zero_copy::{ZeroCopy, ZeroCopyMut};
3
4use crate::{AnchorDeserialize, AnchorSerialize};
5
6#[repr(C)]
7#[derive(
8    AnchorSerialize,
9    AnchorDeserialize,
10    Debug,
11    Clone,
12    Copy,
13    PartialEq,
14    Eq,
15    Default,
16    ZeroCopy,
17    ZeroCopyMut,
18)]
19pub struct CompressedCpiContext {
20    /// Is set by the program that is invoking the CPI to signal that is should
21    /// set the cpi context.
22    pub set_context: bool,
23    /// Is set to clear the cpi context since someone could have set it before
24    /// with unrelated data.
25    pub first_set_context: bool,
26}
27
28impl CompressedCpiContextTrait for ZCompressedCpiContext<'_> {
29    fn first_set_context(&self) -> u8 {
30        if self.first_set_context() {
31            1
32        } else {
33            0
34        }
35    }
36
37    fn set_context(&self) -> u8 {
38        if self.set_context() {
39            1
40        } else {
41            0
42        }
43    }
44}
45
46impl CompressedCpiContextTrait for CompressedCpiContext {
47    fn first_set_context(&self) -> u8 {
48        if self.first_set_context {
49            1
50        } else {
51            0
52        }
53    }
54
55    fn set_context(&self) -> u8 {
56        if self.set_context {
57            1
58        } else {
59            0
60        }
61    }
62}