miclockwork_thread_program/instructions/
thread_resume.rs

1use {crate::state::*, anchor_lang::prelude::*};
2
3/// Accounts required by the `thread_resume` instruction.
4#[derive(Accounts)]
5pub struct ThreadResume<'info> {
6    /// The authority (owner) of the thread.
7    #[account()]
8    pub authority: Signer<'info>,
9
10    /// The thread to be resumed.
11    #[account(
12        mut,
13        seeds = [
14            SEED_THREAD,
15            thread.authority.as_ref(),
16            thread.id.as_slice(),
17        ],
18        bump = thread.bump,
19        has_one = authority
20    )]
21    pub thread: Account<'info, Thread>,
22}
23
24pub fn handler(ctx: Context<ThreadResume>) -> Result<()> {
25    // Get accounts
26    let thread = &mut ctx.accounts.thread;
27
28    // Resume the thread
29    thread.paused = false;
30
31    // Update the exec context
32    match thread.exec_context {
33        None => {}
34        Some(exec_context) => {
35            match exec_context.trigger_context {
36                TriggerContext::Cron { started_at: _ } => {
37                    // Jump ahead to the current timestamp
38                    thread.exec_context = Some(ExecContext {
39                        trigger_context: TriggerContext::Cron {
40                            started_at: Clock::get().unwrap().unix_timestamp,
41                        },
42                        ..exec_context
43                    });
44                }
45                _ => {
46                    // Nothing to do.
47                }
48            }
49        }
50    }
51
52    Ok(())
53}