clockwork_scheduler/instructions/
task_new.rs1use {
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(mut)]
14 pub payer: Signer<'info>,
15
16 #[account(
17 mut,
18 seeds = [
19 SEED_QUEUE,
20 queue.authority.key().as_ref(),
21 queue.name.as_bytes(),
22 ],
23 bump,
24 has_one = authority,
25 )]
26 pub queue: Account<'info, Queue>,
27
28 #[account(address = system_program::ID)]
29 pub system_program: Program<'info, System>,
30
31 #[account(
32 init,
33 seeds = [
34 SEED_TASK,
35 queue.key().as_ref(),
36 queue.task_count.to_be_bytes().as_ref(),
37 ],
38 bump,
39 payer = payer,
40 space = 8 + size_of::<Task>() + borsh::to_vec(&ixs).unwrap().len(),
41 )]
42 pub task: Account<'info, Task>,
43}
44
45pub fn handler(
46 ctx: Context<TaskNew>,
47 ixs: Vec<InstructionData>,
48) -> Result<()> {
49 let task = &mut ctx.accounts.task;
50 let queue = &mut ctx.accounts.queue;
51
52 task.new(ixs, queue)
53}