From a9810157c2fa78075b7c44354fe6350d809c597b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Wed, 12 Jan 2022 16:00:51 +0900 Subject: [PATCH] Add a close instruction so we can shut down existing accounts --- contracts/programs/ocr2/src/context.rs | 11 +++++++++++ contracts/programs/ocr2/src/lib.rs | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/contracts/programs/ocr2/src/context.rs b/contracts/programs/ocr2/src/context.rs index 917f47aeb..95edfc652 100644 --- a/contracts/programs/ocr2/src/context.rs +++ b/contracts/programs/ocr2/src/context.rs @@ -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)] diff --git a/contracts/programs/ocr2/src/lib.rs b/contracts/programs/ocr2/src/lib.rs index 95551163f..8eb8e0759 100644 --- a/contracts/programs/ocr2/src/lib.rs +++ b/contracts/programs/ocr2/src/lib.rs @@ -72,6 +72,12 @@ pub mod ocr2 { Ok(()) } + #[access_control(owner(&ctx.accounts.state, &ctx.accounts.authority))] + pub fn close(ctx: Context) -> 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,