spl_memo_interface/
instruction.rs1use {
2 solana_instruction::{AccountMeta, Instruction},
3 solana_pubkey::Pubkey,
4};
5
6pub fn build_memo(program_id: &Pubkey, memo: &[u8], signer_pubkeys: &[&Pubkey]) -> Instruction {
13 Instruction {
14 program_id: *program_id,
15 accounts: signer_pubkeys
16 .iter()
17 .map(|&pubkey| AccountMeta::new_readonly(*pubkey, true))
18 .collect(),
19 data: memo.to_vec(),
20 }
21}
22
23#[cfg(test)]
24mod tests {
25 use super::*;
26
27 #[test]
28 fn test_build_memo() {
29 let program_id = Pubkey::new_unique();
30 let signer_pubkey = Pubkey::new_unique();
31 let memo = "🐆".as_bytes();
32 let instruction = build_memo(&program_id, memo, &[&signer_pubkey]);
33 assert_eq!(memo, instruction.data);
34 assert_eq!(instruction.accounts.len(), 1);
35 assert_eq!(instruction.accounts[0].pubkey, signer_pubkey);
36 }
37}