miclockwork_thread_program/instructions/
thread_reset.rs

1use {crate::state::*, anchor_lang::prelude::*};
2
3/// Accounts required by the `thread_reset` instruction.
4#[derive(Accounts)]
5pub struct ThreadReset<'info> {
6    /// The authority (owner) of the thread.
7    #[account()]
8    pub authority: Signer<'info>,
9
10    /// The thread to be paused.
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<ThreadReset>) -> Result<()> {
25    // Get accounts
26    let thread = &mut ctx.accounts.thread;
27
28    // Full reset the thread state.
29    thread.next_instruction = None;
30    thread.exec_context = None;
31    thread.created_at = Clock::get().unwrap().into();
32
33    Ok(())
34}