1use {solana_instruction::Instruction, solana_pubkey::Pubkey, spl_memo_interface::v3::id};
2
3pub trait WithMemo {
4 fn with_memo<T: AsRef<str>>(self, memo: Option<T>) -> Self;
5}
6
7impl WithMemo for Vec<Instruction> {
8 fn with_memo<T: AsRef<str>>(mut self, memo: Option<T>) -> Self {
9 if let Some(memo) = &memo {
10 let memo = memo.as_ref();
11 let memo_ix = Instruction {
12 program_id: Pubkey::from(id().to_bytes()),
13 accounts: vec![],
14 data: memo.as_bytes().to_vec(),
15 };
16 self.push(memo_ix);
17 }
18 self
19 }
20}