Created
April 9, 2022 03:15
-
-
Save alecchendev/6106141e2fbf41ed1b7baccde5533c3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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