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
use {
crate::{
error::TokenError,
extension::{BaseStateWithExtensions, Extension, ExtensionType, StateWithExtensionsMut},
pod::PodBool,
state::Account,
},
bytemuck::{Pod, Zeroable},
solana_program::{
instruction::get_processed_sibling_instruction, program_error::ProgramError, 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> {
let is_memo_program = |program_id: &Pubkey| -> bool {
program_id == &safe_memo::id() || program_id == &safe_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(())
}