antegen_thread_program/instructions/
thread_delete.rs1use crate::{errors::AntegenThreadError, state::ThreadConfig, *};
2use anchor_lang::prelude::*;
3
4#[derive(Accounts)]
7pub struct ThreadDelete<'info> {
8 #[account(
10 mut,
11 constraint = admin.key() == config.admin @ AntegenThreadError::InvalidConfigAdmin,
12 )]
13 pub admin: Signer<'info>,
14
15 #[account(
17 seeds = [SEED_CONFIG],
18 bump = config.bump,
19 )]
20 pub config: Account<'info, ThreadConfig>,
21
22 #[account(mut)]
24 pub thread: UncheckedAccount<'info>,
25}
26
27pub fn thread_delete(ctx: Context<ThreadDelete>) -> Result<()> {
28 let admin = &ctx.accounts.admin;
29 let thread = &ctx.accounts.thread;
30
31 let thread_lamports = thread.lamports();
33 **thread.try_borrow_mut_lamports()? -= thread_lamports;
34 **admin.try_borrow_mut_lamports()? += thread_lamports;
35
36 thread.try_borrow_mut_data()?.fill(0);
38
39 msg!("Deleting thread (admin)");
40 Ok(())
41}