Skip to content

Commit 4798391

Browse files
mvinesjoncinque
authored andcommitted
Reorganize crates based on program
1 parent ef04082 commit 4798391

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

program/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Memo Program
2+
3+
A simple program that validates a string of UTF-8 encoded characters. It can be
4+
used to record a string on-chain, stored in the instruction data of a successful
5+
transaction.
6+
7+
Full documentation is available at https://spl.solana.com

program/src/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
# Note: This crate must be built using do.sh
3+
4+
[package]
5+
name = "spl-memo"
6+
version = "1.0.7"
7+
description = "Solana Program Library Memo"
8+
authors = ["Solana Maintainers <[email protected]>"]
9+
repository = "https://github.com/solana-labs/solana-program-library"
10+
license = "Apache-2.0"
11+
edition = "2018"
12+
13+
[features]
14+
no-entrypoint = []
15+
skip-no-mangle = ["solana-sdk/skip-no-mangle"]
16+
program = ["solana-sdk/program"]
17+
default = ["solana-sdk/default"]
18+
19+
[dependencies]
20+
solana-sdk = { version = "1.2.17", default-features = false, optional = true }
21+
22+
[lib]
23+
name = "spl_memo"
24+
crate-type = ["cdylib", "lib"]

program/src/entrypoint.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//! Program entrypoint definitions
2+
3+
#![cfg(feature = "program")]
4+
#![cfg(not(feature = "no-entrypoint"))]
5+
6+
use solana_sdk::{
7+
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, program_error::ProgramError,
8+
pubkey::Pubkey,
9+
};
10+
use std::str::from_utf8;
11+
12+
entrypoint!(process_instruction);
13+
fn process_instruction<'a>(
14+
_program_id: &Pubkey,
15+
_accounts: &'a [AccountInfo<'a>],
16+
instruction_data: &[u8],
17+
) -> ProgramResult {
18+
from_utf8(instruction_data).map_err(|_| ProgramError::InvalidInstructionData)?;
19+
Ok(())
20+
}
21+
22+
// Pull in syscall stubs when building for non-BPF targets
23+
#[cfg(not(target_arch = "bpf"))]
24+
solana_sdk::program_stubs!();
25+
26+
#[cfg(test)]
27+
mod tests {
28+
use super::*;
29+
use solana_sdk::{program_error::ProgramError, pubkey::Pubkey};
30+
31+
#[test]
32+
fn test_utf8_memo() {
33+
let program_id = Pubkey::new(&[0; 32]);
34+
35+
let string = b"letters and such";
36+
assert_eq!(Ok(()), process_instruction(&program_id, &[], string));
37+
38+
let emoji = "🐆".as_bytes();
39+
let bytes = [0xF0, 0x9F, 0x90, 0x86];
40+
assert_eq!(emoji, bytes);
41+
assert_eq!(Ok(()), process_instruction(&program_id, &[], &emoji));
42+
43+
let mut bad_utf8 = bytes;
44+
bad_utf8[3] = 0xFF; // Invalid UTF-8 byte
45+
assert_eq!(
46+
Err(ProgramError::InvalidInstructionData),
47+
process_instruction(&program_id, &[], &bad_utf8)
48+
);
49+
}
50+
}

program/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![deny(missing_docs)]
2+
3+
//! A simple program that accepts a string of encoded characters and verifies that it parses. Currently handles UTF-8.
4+
5+
pub mod entrypoint;
6+
7+
// Export current solana-sdk types for downstream users who may also be building with a different
8+
// solana-sdk version
9+
pub use solana_sdk;
10+
11+
solana_sdk::declare_id!("Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo");

0 commit comments

Comments
 (0)