safe_memo/
lib.rs

1#![deny(missing_docs)]
2
3//! A program that accepts a string of encoded characters and verifies that it parses,
4//! while verifying and logging signers. Currently handles UTF-8 characters.
5
6mod entrypoint;
7pub mod processor;
8
9// Export current sdk types for downstream users building with a different sdk version
10pub use solana_program;
11use solana_program::{
12    instruction::{AccountMeta, Instruction},
13    pubkey::Pubkey,
14};
15
16/// Legacy symbols from Memo v1
17pub mod v1 {
18    solana_program::declare_id!("MEMDqRW2fYAU19mcFnoDVoqG4Br4t7TdyWjjv38P6Nc");
19}
20
21solana_program::declare_id!("MEMWKbqsjEB8o972BvDHExZFSauzGZKvB4xHDVPFowh");
22
23/// Build a memo instruction, possibly signed
24///
25/// Accounts expected by this instruction:
26///
27///   0. ..0+N. `[signer]` Expected signers; if zero provided, instruction will be processed as a
28///     normal, unsigned safe-memo
29///
30pub fn build_memo(memo: &[u8], signer_pubkeys: &[&Pubkey]) -> Instruction {
31    Instruction {
32        program_id: id(),
33        accounts: signer_pubkeys
34            .iter()
35            .map(|&pubkey| AccountMeta::new_readonly(*pubkey, true))
36            .collect(),
37        data: memo.to_vec(),
38    }
39}
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn test_build_memo() {
47        let signer_pubkey = Pubkey::new_unique();
48        let memo = "🐆".as_bytes();
49        let instruction = build_memo(memo, &[&signer_pubkey]);
50        assert_eq!(memo, instruction.data);
51        assert_eq!(instruction.accounts.len(), 1);
52        assert_eq!(instruction.accounts[0].pubkey, signer_pubkey);
53    }
54}