Skip to content

Commit

Permalink
Add a close instruction so we can shut down existing accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Jan 12, 2022
1 parent cf40ab1 commit a981015
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions contracts/programs/ocr2/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ pub struct Initialize<'info> {
pub associated_token_program: Program<'info, AssociatedToken>,
}

#[derive(Accounts)]
pub struct Close<'info> {
#[account(mut, close = receiver)]
pub state: AccountLoader<'info, State>,
#[account(mut, close = receiver)]
pub transmissions: AccountLoader<'info, Transmissions>,
#[account(mut)]
pub receiver: SystemAccount<'info>,
pub authority: Signer<'info>,
}

#[derive(Accounts)]
pub struct TransferOwnership<'info> {
#[account(mut)]
Expand Down
6 changes: 6 additions & 0 deletions contracts/programs/ocr2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ pub mod ocr2 {
Ok(())
}

#[access_control(owner(&ctx.accounts.state, &ctx.accounts.authority))]
pub fn close(ctx: Context<Close>) -> ProgramResult {
// NOTE: Close is handled by anchor on exit due to the `close` attribute
Ok(())
}

#[access_control(owner(&ctx.accounts.state, &ctx.accounts.authority))]
pub fn transfer_ownership(
ctx: Context<TransferOwnership>,
Expand Down

0 comments on commit a981015

Please sign in to comment.