miclockwork_network_program/jobs/delete_snapshot/
job.rs

1use anchor_lang::{prelude::*, solana_program::instruction::Instruction, InstructionData};
2use miclockwork_utils::thread::ThreadResponse;
3
4use crate::state::*;
5
6#[derive(Accounts)]
7pub struct DeleteSnapshotJob<'info> {
8    #[account(address = Config::pubkey())]
9    pub config: Account<'info, Config>,
10
11    #[account(
12        address = Registry::pubkey(),
13        constraint = !registry.locked
14    )]
15    pub registry: Account<'info, Registry>,
16
17    #[account(address = config.epoch_thread)]
18    pub thread: Signer<'info>,
19}
20
21pub fn handler(ctx: Context<DeleteSnapshotJob>) -> Result<ThreadResponse> {
22    let config = &ctx.accounts.config;
23    let registry = &ctx.accounts.registry;
24    let thread = &mut ctx.accounts.thread;
25
26    Ok(ThreadResponse {
27        dynamic_instruction: Some(
28            Instruction {
29                program_id: crate::ID,
30                accounts: crate::accounts::DeleteSnapshotProcessSnapshot {
31                    config: config.key(),
32                    registry: registry.key(),
33                    snapshot: Snapshot::pubkey(registry.current_epoch.checked_sub(1).unwrap()),
34                    thread: thread.key(),
35                }
36                .to_account_metas(Some(true)),
37                data: crate::instruction::DeleteSnapshotProcessSnapshot {}.data(),
38            }
39            .into(),
40        ),
41        close_to: None,
42        trigger: None,
43    })
44}