cronos_scheduler/instructions/
task_new.rs

1use {
2    crate::state::*,
3    anchor_lang::{prelude::*, solana_program::system_program},
4    std::mem::size_of
5};
6
7#[derive(Accounts)]
8#[instruction(ixs: Vec<InstructionData>)]
9pub struct TaskNew<'info> {
10    #[account()]
11    pub authority: Signer<'info>,
12
13    #[account(
14        seeds = [
15            SEED_MANAGER, 
16            manager.authority.as_ref()
17        ],
18        bump,
19        has_one = authority,
20    )]
21    pub manager: Account<'info, Manager>,
22
23    #[account(mut)]
24    pub payer: Signer<'info>,
25
26    #[account(
27        mut,
28        seeds = [
29            SEED_QUEUE, 
30            manager.key().as_ref(),
31            queue.id.to_be_bytes().as_ref(),
32        ],
33        bump,
34        has_one = manager,
35    )]
36    pub queue: Account<'info, Queue>,
37
38    #[account(address = system_program::ID)]
39    pub system_program: Program<'info, System>,
40
41    #[account(
42        init,
43        seeds = [
44            SEED_TASK, 
45            queue.key().as_ref(),
46            queue.task_count.to_be_bytes().as_ref(),
47        ],
48        bump,
49        payer = payer,
50        space = 8 + size_of::<Task>() + borsh::to_vec(&ixs).unwrap().len(),
51    )]
52    pub task: Account<'info, Task>,
53}
54
55pub fn handler(
56    ctx: Context<TaskNew>,
57    ixs: Vec<InstructionData>,
58) -> Result<()> {
59    let task = &mut ctx.accounts.task;
60    let queue = &mut ctx.accounts.queue;
61
62    task.new(ixs, queue)
63}