Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions program/src/processor/close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,24 @@ pub fn close(accounts: &[AccountInfo]) -> ProgramResult {

// account
// - must have data
// - authority must match (if not a keypair buffer)
// - authority must match

let account_data = if account.data_is_empty() {
return Err(ProgramError::UninitializedAccount);
} else {
unsafe { account.borrow_data_unchecked() }
};

// We only need to validate the authority if it is not a keypair buffer,
// since we already validated that the authority is a signer.
if account.key() != authority.key() {
match AccountDiscriminator::try_from(account_data[0])? {
AccountDiscriminator::Buffer => {
let buffer = unsafe { Buffer::from_bytes_unchecked(account_data) };
validate_authority(buffer, authority, program, program_data)?
}
AccountDiscriminator::Metadata => {
let header = validate_metadata(account)?;
validate_authority(header, authority, program, program_data)?
}
_ => return Err(ProgramError::InvalidAccountData),
match AccountDiscriminator::try_from(account_data[0])? {
AccountDiscriminator::Buffer => {
let buffer = unsafe { Buffer::from_bytes_unchecked(account_data) };
validate_authority(buffer, authority, program, program_data)?
}
AccountDiscriminator::Metadata => {
let header = validate_metadata(account)?;
validate_authority(header, authority, program, program_data)?
}
_ => return Err(ProgramError::InvalidAccountData),
}

// Move the lamports to the destination account and close the account.
Expand Down
Loading