1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use {crate::state::*, anchor_lang::prelude::*};

/// Accounts required by the `thread_resume` instruction.
#[derive(Accounts)]
pub struct ThreadResume<'info> {
    /// The authority (owner) of the thread.
    #[account()]
    pub authority: Signer<'info>,

    /// The thread to be resumed.
    #[account(
        mut,
        seeds = [
            SEED_THREAD,
            thread.authority.as_ref(),
            thread.id.as_slice(),
        ],
        bump = thread.bump,
        has_one = authority
    )]
    pub thread: Account<'info, Thread>,
}

pub fn handler(ctx: Context<ThreadResume>) -> Result<()> {
    // Get accounts
    let thread = &mut ctx.accounts.thread;

    // Resume the thread
    thread.paused = false;

    // Update the exec context
    match thread.exec_context {
        None => {}
        Some(exec_context) => {
            match exec_context.trigger_context {
                TriggerContext::Cron { started_at: _ } => {
                    // Jump ahead to the current timestamp
                    thread.exec_context = Some(ExecContext {
                        trigger_context: TriggerContext::Cron {
                            started_at: Clock::get().unwrap().unix_timestamp,
                        },
                        ..exec_context
                    });
                }
                _ => {
                    // Nothing to do.
                }
            }
        }
    }

    Ok(())
}