Skip to content

Commit

Permalink
feat: Use new canonical close account pattern (coral-xyz#2169)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arrowana authored and henrye committed Dec 6, 2022
1 parent 280ab02 commit 3d030ce
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The minor version will be incremented upon a breaking change and the patch versi
* spl: Add `create_metadata_accounts_v3` and `set_collection_size` wrappers ([#2119](https://github.com/coral-xyz/anchor/pull/2119))
* spl: Add `MetadataAccount` account deserialization. ([#2014](https://github.com/coral-xyz/anchor/pull/2014)).
* lang: Add parsing for consts from impl blocks for IDL PDA seeds generation ([#2128](https://github.com/coral-xyz/anchor/pull/2014))
* lang: Account closing reassigns to system program and reallocates ([#2169](https://github.com/coral-xyz/anchor/pull/2169)).
* ts: Add coders for SPL programs ([#2143](https://github.com/coral-xyz/anchor/pull/2143)).

### Fixes
Expand Down
14 changes: 3 additions & 11 deletions lang/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use crate::bpf_writer::BpfWriter;
use crate::error::ErrorCode;
use crate::prelude::error;
use crate::Result;
use solana_program::account_info::AccountInfo;
use std::io::Write;
use solana_program::system_program;

pub fn close<'info>(info: AccountInfo<'info>, sol_destination: AccountInfo<'info>) -> Result<()> {
// Transfer tokens from the account to the sol_destination.
Expand All @@ -12,11 +9,6 @@ pub fn close<'info>(info: AccountInfo<'info>, sol_destination: AccountInfo<'info
dest_starting_lamports.checked_add(info.lamports()).unwrap();
**info.lamports.borrow_mut() = 0;

// Mark the account discriminator as closed.
let mut data = info.try_borrow_mut_data()?;
let dst: &mut [u8] = &mut data;
let mut writer = BpfWriter::new(dst);
writer
.write_all(&crate::__private::CLOSED_ACCOUNT_DISCRIMINATOR)
.map_err(|_| error!(ErrorCode::AccountDidNotSerialize))
info.assign(&system_program::ID);
info.realloc(0, false).map_err(Into::into)
}

0 comments on commit 3d030ce

Please sign in to comment.