forked from solana-foundation/anchor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.rs
More file actions
19 lines (16 loc) · 701 Bytes
/
common.rs
File metadata and controls
19 lines (16 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use crate::prelude::{Id, System};
use crate::Result;
use solana_program::account_info::AccountInfo;
use solana_sdk_ids::system_program;
pub fn close<'info>(info: AccountInfo<'info>, sol_destination: AccountInfo<'info>) -> Result<()> {
// Transfer tokens from the account to the sol_destination.
let dest_starting_lamports = sol_destination.lamports();
**sol_destination.lamports.borrow_mut() =
dest_starting_lamports.checked_add(info.lamports()).unwrap();
**info.lamports.borrow_mut() = 0;
info.assign(&system_program::ID);
info.resize(0).map_err(Into::into)
}
pub fn is_closed(info: &AccountInfo) -> bool {
info.owner == &System::id() && info.data_is_empty()
}