Allow closing upgradeable program accounts (#19319)
This commit is contained in:
@ -196,6 +196,10 @@ pub fn is_set_authority_instruction(instruction_data: &[u8]) -> bool {
|
||||
!instruction_data.is_empty() && 4 == instruction_data[0]
|
||||
}
|
||||
|
||||
pub fn is_close_instruction(instruction_data: &[u8]) -> bool {
|
||||
!instruction_data.is_empty() && 5 == instruction_data[0]
|
||||
}
|
||||
|
||||
/// Returns the instructions required to set a buffers's authority.
|
||||
pub fn set_buffer_authority(
|
||||
buffer_address: &Pubkey,
|
||||
@ -231,17 +235,37 @@ pub fn set_upgrade_authority(
|
||||
Instruction::new_with_bincode(id(), &UpgradeableLoaderInstruction::SetAuthority, metas)
|
||||
}
|
||||
|
||||
/// Returns the instructions required to close an account
|
||||
/// Returns the instructions required to close a buffer account
|
||||
pub fn close(
|
||||
close_address: &Pubkey,
|
||||
recipient_address: &Pubkey,
|
||||
authority_address: &Pubkey,
|
||||
) -> Instruction {
|
||||
let metas = vec![
|
||||
close_any(
|
||||
close_address,
|
||||
recipient_address,
|
||||
Some(authority_address),
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns the instructions required to close program, buffer, or uninitialized account
|
||||
pub fn close_any(
|
||||
close_address: &Pubkey,
|
||||
recipient_address: &Pubkey,
|
||||
authority_address: Option<&Pubkey>,
|
||||
program_address: Option<&Pubkey>,
|
||||
) -> Instruction {
|
||||
let mut metas = vec![
|
||||
AccountMeta::new(*close_address, false),
|
||||
AccountMeta::new(*recipient_address, false),
|
||||
AccountMeta::new_readonly(*authority_address, true),
|
||||
];
|
||||
if let Some(authority_address) = authority_address {
|
||||
metas.push(AccountMeta::new(*authority_address, true));
|
||||
}
|
||||
if let Some(program_address) = program_address {
|
||||
metas.push(AccountMeta::new(*program_address, false));
|
||||
}
|
||||
Instruction::new_with_bincode(id(), &UpgradeableLoaderInstruction::Close, metas)
|
||||
}
|
||||
|
||||
|
@ -117,8 +117,12 @@ pub enum UpgradeableLoaderInstruction {
|
||||
/// withdraws all the lamports
|
||||
///
|
||||
/// # Account references
|
||||
/// 0. `[writable]` The account to close.
|
||||
/// 0. `[writable]` The account to close, if closing a program must be the
|
||||
/// ProgramData account.
|
||||
/// 1. `[writable]` The account to deposit the closed account's lamports.
|
||||
/// 2. `[signer]` The account's authority.
|
||||
/// 2. `[signer]` The account's authority, Optional, required for
|
||||
/// initialized accounts.
|
||||
/// 3. `[writable]` The associated Program account if the account to close
|
||||
/// is a ProgramData account.
|
||||
Close,
|
||||
}
|
||||
|
Reference in New Issue
Block a user