spl_token_2022/extension/memo_transfer/
mod.rs#[cfg(feature = "serde-traits")]
use serde::{Deserialize, Serialize};
use {
crate::{
error::TokenError,
extension::{BaseState, BaseStateWithExtensions, Extension, ExtensionType},
},
bytemuck::{Pod, Zeroable},
solana_program::{
instruction::get_processed_sibling_instruction, program_error::ProgramError, pubkey::Pubkey,
},
spl_pod::primitives::PodBool,
};
pub mod instruction;
pub mod processor;
#[repr(C)]
#[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))]
#[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<BSE: BaseStateWithExtensions<S>, S: BaseState>(account_state: &BSE) -> 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 == &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(())
}