use {
crate::objects::*,
anchor_lang::{prelude::*, solana_program::system_program},
std::mem::size_of,
};
#[derive(Accounts)]
#[instruction(id: String, kickoff_instruction: InstructionData, trigger: Trigger)]
pub struct QueueCreate<'info> {
#[account()]
pub authority: Signer<'info>,
#[account(mut)]
pub payer: Signer<'info>,
#[account(
init,
address = Queue::pubkey(authority.key(), id),
payer = payer,
space = vec![
8,
size_of::<Queue>(),
id.as_bytes().len(),
kickoff_instruction.try_to_vec()?.len(),
trigger.try_to_vec()?.len()
].iter().sum()
)]
pub queue: Account<'info, Queue>,
#[account(address = system_program::ID)]
pub system_program: Program<'info, System>,
}
pub fn handler(ctx: Context<QueueCreate>, id: String, kickoff_instruction: InstructionData, trigger: Trigger) -> Result<()> {
let authority = &ctx.accounts.authority;
let queue = &mut ctx.accounts.queue;
queue.init(authority.key(), id, kickoff_instruction, trigger)?;
Ok(())
}