From 2b93141c05a878573dcc5b9ced4d513faab5e7fb Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 11 Aug 2023 15:15:29 -0600 Subject: [PATCH] transfer hook example with PDAs --- token/transfer-hook-example/src/processor.rs | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/token/transfer-hook-example/src/processor.rs b/token/transfer-hook-example/src/processor.rs index fccd0ba0bae..e38cf84f2f4 100644 --- a/token/transfer-hook-example/src/processor.rs +++ b/token/transfer-hook-example/src/processor.rs @@ -36,6 +36,27 @@ fn check_token_account_is_transferring(account_info: &AccountInfo) -> Result<(), } } +fn check_extra_meta( + account_info: &AccountInfo, + extra_meta: &AccountMeta, +) -> Result<(), ProgramError> { + if !(&extra_meta.pubkey == account_info.key + && extra_meta.is_signer == account_info.is_signer + && extra_meta.is_writable == account_info.is_writable) + { + return Err(TransferHookError::IncorrectAccount.into()); + } + Ok(()) +} + +fn next_extra_account_meta<'a>( + extra_account_metas_iter: &mut impl Iterator, +) -> Result<&'a ExtraAccountMeta, ProgramError> { + extra_account_metas_iter + .next() + .ok_or(ProgramError::NotEnoughAccountKeys) +} + /// Processes an [Execute](enum.TransferHookInstruction.html) instruction. pub fn process_execute( program_id: &Pubkey,