spl_memo/
lib.rs

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