1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use {
crate::{
extension::{Extension, ExtensionType, StateWithExtensionsMut},
pod::PodBool,
state::Account,
},
bytemuck::{Pod, Zeroable},
solana_program::program_error::ProgramError,
};
#[cfg(feature = "sibling-instruction")]
use {
crate::error::TokenError,
solana_program::{instruction::get_processed_sibling_instruction, pubkey::Pubkey},
};
pub mod instruction;
pub mod processor;
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
pub struct MemoTransfer {
pub require_incoming_transfer_memos: PodBool,
}
impl Extension for MemoTransfer {
const TYPE: ExtensionType = ExtensionType::MemoTransfer;
}
pub fn memo_required(account_state: &StateWithExtensionsMut<Account>) -> bool {
if let Ok(extension) = account_state.get_extension::<MemoTransfer>() {
return extension.require_incoming_transfer_memos.into();
}
false
}
pub fn check_previous_sibling_instruction_is_memo() -> Result<(), ProgramError> {
#[cfg(feature = "sibling-instruction")]
{
let is_memo_program = |program_id: &Pubkey| -> bool {
program_id == &spl_memo::id() || program_id == &spl_memo::v1::id()
};
let previous_instruction = get_processed_sibling_instruction(0);
match previous_instruction {
Some(instruction) if is_memo_program(&instruction.program_id) => {}
_ => {
return Err(TokenError::NoMemo.into());
}
}
}
Ok(())
}