clockwork_crank/instructions/
queue_create.rs

1use {
2    crate::state::*,
3    anchor_lang::{prelude::*, solana_program::system_program},
4    std::mem::size_of,
5};
6
7
8#[derive(Accounts)]
9#[instruction(id: String, kickoff_instruction: InstructionData, trigger: Trigger)]
10pub struct QueueCreate<'info> {
11    #[account()]
12    pub authority: Signer<'info>,
13
14    #[account(mut)]
15    pub payer: Signer<'info>,
16
17    #[account(
18        init,
19        seeds = [
20            SEED_QUEUE, 
21            authority.key().as_ref(),
22            id.as_bytes(),
23        ],
24        bump,
25        payer = payer,
26        space = vec![
27            8, 
28            size_of::<Queue>(), 
29            id.as_bytes().len(),
30            kickoff_instruction.try_to_vec()?.len(),  
31            trigger.try_to_vec()?.len()
32        ].iter().sum()
33    )]
34    pub queue: Account<'info, Queue>,
35
36    #[account(address = system_program::ID)]
37    pub system_program: Program<'info, System>,
38}
39
40pub fn handler(ctx: Context<QueueCreate>, id: String, kickoff_instruction: InstructionData, trigger: Trigger) -> Result<()> {
41    // Get accounts
42    let authority = &ctx.accounts.authority;
43    let queue = &mut ctx.accounts.queue;
44
45    // Initialize the queue
46    queue.init(authority.key(), id, kickoff_instruction, trigger)?;
47
48    Ok(())
49}