clockwork_scheduler/instructions/
queue_withdraw.rs1use {
2 crate::state::*,
3 anchor_lang::prelude::*,
4};
5
6#[derive(Accounts)]
7#[instruction(amount: u64)]
8pub struct QueueWithdraw<'info> {
9 #[account()]
10 pub authority: Signer<'info>,
11
12 #[account(mut)]
13 pub pay_to: SystemAccount<'info>,
14
15 #[account(
16 mut,
17 seeds = [
18 SEED_QUEUE,
19 queue.authority.key().as_ref(),
20 queue.name.as_bytes(),
21 ],
22 bump,
23 has_one = authority,
24 )]
25 pub queue: Account<'info, Queue>,
26}
27
28pub fn handler(ctx: Context<QueueWithdraw>, amount: u64) -> Result<()> {
29 let pay_to = &mut ctx.accounts.pay_to;
31 let queue = &mut ctx.accounts.queue;
32
33 **queue.to_account_info().try_borrow_mut_lamports()? = queue
35 .to_account_info()
36 .lamports()
37 .checked_sub(amount)
38 .unwrap();
39 **pay_to.to_account_info().try_borrow_mut_lamports()? = pay_to
40 .to_account_info()
41 .lamports()
42 .checked_add(amount)
43 .unwrap();
44
45 Ok(())
46}