Skip to content

Commit

Permalink
Switching to try borrow.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Oct 31, 2024
1 parent c5ad4d5 commit e3439dc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core/rust/utils/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,19 @@ pub fn close_account_raw<'a>(
src_account_info: &AccountInfo<'a>,
) -> ProgramResult {
let dest_starting_lamports = dest_account_info.lamports();
**dest_account_info.lamports.borrow_mut() = dest_starting_lamports
let mut dest_lamports_mut = dest_account_info
.lamports
.try_borrow_mut()
.map_err(|_| ProgramError::AccountBorrowFailed)?;
**dest_lamports_mut = dest_starting_lamports
.checked_add(src_account_info.lamports())
.ok_or(ProgramError::InvalidRealloc)?;
**src_account_info.lamports.borrow_mut() = 0;

let mut src_lamports_mut = src_account_info
.lamports
.try_borrow_mut()
.map_err(|_| ProgramError::AccountBorrowFailed)?;
**src_lamports_mut = 0;

src_account_info.assign(&system_program::ID);
src_account_info.realloc(0, false).map_err(Into::into)
Expand Down

0 comments on commit e3439dc

Please sign in to comment.