From c221c16994bab8b33eaf3a4ee0ebdfe0194e4ee7 Mon Sep 17 00:00:00 2001 From: blockiosaurus Date: Sat, 6 Apr 2024 13:19:09 -0400 Subject: [PATCH] Adding a new assert_derivation for when the bump is known. --- core/rust/utils/src/assertions.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/rust/utils/src/assertions.rs b/core/rust/utils/src/assertions.rs index 627f0bfae0..dd1c993c65 100644 --- a/core/rust/utils/src/assertions.rs +++ b/core/rust/utils/src/assertions.rs @@ -66,6 +66,19 @@ pub fn assert_derivation( Ok(bump) } +pub fn assert_derivation_with_bump( + program_id: &Pubkey, + account: &AccountInfo, + path: &[&[u8]], + error: impl Into, +) -> Result<(), ProgramError> { + let key = Pubkey::create_program_address(path, program_id)?; + if key != *account.key { + return Err(error.into()); + } + Ok(()) +} + pub fn assert_rent_exempt( rent: &Rent, account_info: &AccountInfo,