sablier_thread_program/instructions/
thread_resume.rs

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