#[allow(deprecated)]
use crate::accounts::program_account::ProgramAccount;
use crate::prelude::*;
use solana_program::pubkey::Pubkey;
pub const IDL_IX_TAG: u64 = 0x0a69e9a778bcf440;
pub const ERASED_AUTHORITY: Pubkey = Pubkey::new_from_array([0u8; 32]);
#[derive(AnchorSerialize, AnchorDeserialize)]
pub enum IdlInstruction {
Create { data_len: u64 },
CreateBuffer,
Write { data: Vec<u8> },
SetBuffer,
SetAuthority { new_authority: Pubkey },
}
pub type IdlCreateAccounts<'info> = crate::ctor::Ctor<'info>;
#[derive(Accounts)]
pub struct IdlAccounts<'info> {
#[account(mut, has_one = authority)]
#[allow(deprecated)]
pub idl: ProgramAccount<'info, IdlAccount>,
#[account(constraint = authority.key != &ERASED_AUTHORITY)]
pub authority: Signer<'info>,
}
#[derive(Accounts)]
pub struct IdlCreateBuffer<'info> {
#[account(zero)]
#[allow(deprecated)]
pub buffer: ProgramAccount<'info, IdlAccount>,
#[account(constraint = authority.key != &ERASED_AUTHORITY)]
pub authority: Signer<'info>,
}
#[derive(Accounts)]
pub struct IdlSetBuffer<'info> {
#[account(mut, constraint = buffer.authority == idl.authority)]
#[allow(deprecated)]
pub buffer: ProgramAccount<'info, IdlAccount>,
#[account(mut, has_one = authority)]
#[allow(deprecated)]
pub idl: ProgramAccount<'info, IdlAccount>,
#[account(constraint = authority.key != &ERASED_AUTHORITY)]
pub authority: Signer<'info>,
}
#[account("internal")]
#[derive(Debug)]
pub struct IdlAccount {
pub authority: Pubkey,
pub data: Vec<u8>,
}
impl IdlAccount {
pub fn address(program_id: &Pubkey) -> Pubkey {
let program_signer = Pubkey::find_program_address(&[], program_id).0;
Pubkey::create_with_seed(&program_signer, IdlAccount::seed(), program_id)
.expect("Seed is always valid")
}
pub fn seed() -> &'static str {
"anchor:idl"
}
}