Skip to content

Instantly share code, notes, and snippets.

@alecchendev
Created April 9, 2022 03:15
Show Gist options
  • Save alecchendev/6106141e2fbf41ed1b7baccde5533c3a to your computer and use it in GitHub Desktop.
Save alecchendev/6106141e2fbf41ed1b7baccde5533c3a to your computer and use it in GitHub Desktop.
use solana_program::{entrypoint::ProgramResult, msg, program_error::ProgramError};
pub fn assert_msg(statement: bool, err: ProgramError, msg: &str) -> ProgramResult {
if !statement {
msg!(msg);
Err(err)
} else {
Ok(())
}
}
// usage
assert_msg(
*pda_ai.key == pda,
MyError::WrongPDA.into(),
"PDA for user was invalid.",
)?;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment