I have a program which should be allowed to be called by whitelisted programs only.
Currently I solved the issue as such, but I wonder whether there are other more elegant solutions (maybe, by using Instructions
sysvar, just like Metaplex does).
#[derive(Accounts)]
#[instruction(caller_id: Pubkey, caller_bump: u8)]
pub struct Whitelisted<'info> {
#[account(
seeds = [crate::SIGNATURE],
bump = caller_bump,
seeds::program = caller_id,
)]
pub caller_signature: Signer<'info>,
#[account(
constraint = state.can_be_called_by(caller_id),
)]
pub state: Account<'info, State>,
}
---snip---
pub fn whitelisted(
ctx: Context<Whitelisted>,
_caller_id: Pubkey,
_called_bump: u8,
) -> anchor_lang::Result<()> {
---snip---
}
And I have a caller sign caller_signature
pda account with invoke_signed
and also pass its address with a bump, which were stored beforehand.