I have an Anchor program where one of the instruction calls another like so:
#[program]
pub mod dippies_index_protocol {
use super::*;
pub fn foo(
ctx: Context<Foo>,
) -> Result<()> {
instructions::bar(ctx)
}
pub fn bar(
ctx: Context<Bar>,
) -> Result<()> {
Ok(())
}
}
However, I want the signer of the foo instruction to be the signer of the transaction, and the signer of the bar transaction when called by foo to be a PDA.
I can't use CpiContext::new_with_signer
because it's not a cross program invocation, I can't instantiate a signer that wasn't passed to to the #[derive(Accounts)]
struct and I can't pass it because only the program can sign with this key.
Is there a way to do CPIs to the same program? Can I instantiate a Signer
?