Make payer and system program optional when extending lookup tables (#23678)
This commit is contained in:
@ -38,13 +38,16 @@ pub enum ProgramInstruction {
|
||||
/// 1. `[SIGNER]` Current authority
|
||||
FreezeLookupTable,
|
||||
|
||||
/// Extend an address lookup table with new addresses
|
||||
/// Extend an address lookup table with new addresses. Funding account and
|
||||
/// system program account references are only required if the lookup table
|
||||
/// account requires additional lamports to cover the rent-exempt balance
|
||||
/// after being extended.
|
||||
///
|
||||
/// # Account references
|
||||
/// 0. `[WRITE]` Address lookup table account to extend
|
||||
/// 1. `[SIGNER]` Current authority
|
||||
/// 2. `[SIGNER, WRITE]` Account that will fund the table reallocation
|
||||
/// 3. `[]` System program for CPI.
|
||||
/// 2. `[SIGNER, WRITE, OPTIONAL]` Account that will fund the table reallocation
|
||||
/// 3. `[OPTIONAL]` System program for CPI.
|
||||
ExtendLookupTable { new_addresses: Vec<Pubkey> },
|
||||
|
||||
/// Deactivate an address lookup table, making it unusable and
|
||||
@ -120,18 +123,25 @@ pub fn freeze_lookup_table(lookup_table_address: Pubkey, authority_address: Pubk
|
||||
pub fn extend_lookup_table(
|
||||
lookup_table_address: Pubkey,
|
||||
authority_address: Pubkey,
|
||||
payer_address: Pubkey,
|
||||
payer_address: Option<Pubkey>,
|
||||
new_addresses: Vec<Pubkey>,
|
||||
) -> Instruction {
|
||||
let mut accounts = vec![
|
||||
AccountMeta::new(lookup_table_address, false),
|
||||
AccountMeta::new_readonly(authority_address, true),
|
||||
];
|
||||
|
||||
if let Some(payer_address) = payer_address {
|
||||
accounts.extend([
|
||||
AccountMeta::new(payer_address, true),
|
||||
AccountMeta::new_readonly(system_program::id(), false),
|
||||
]);
|
||||
}
|
||||
|
||||
Instruction::new_with_bincode(
|
||||
id(),
|
||||
&ProgramInstruction::ExtendLookupTable { new_addresses },
|
||||
vec![
|
||||
AccountMeta::new(lookup_table_address, false),
|
||||
AccountMeta::new_readonly(authority_address, true),
|
||||
AccountMeta::new(payer_address, true),
|
||||
AccountMeta::new_readonly(system_program::id(), false),
|
||||
],
|
||||
accounts,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -225,15 +225,6 @@ impl Processor {
|
||||
return Err(InstructionError::MissingRequiredSignature);
|
||||
}
|
||||
|
||||
let payer_account =
|
||||
keyed_account_at_index(keyed_accounts, checked_add(first_instruction_account, 2)?)?;
|
||||
let payer_key = if let Some(payer_key) = payer_account.signer_key() {
|
||||
*payer_key
|
||||
} else {
|
||||
ic_msg!(invoke_context, "Payer account must be a signer");
|
||||
return Err(InstructionError::MissingRequiredSignature);
|
||||
};
|
||||
|
||||
let lookup_table_account_ref = lookup_table_account.try_account_ref()?;
|
||||
let lookup_table_data = lookup_table_account_ref.data();
|
||||
let mut lookup_table = AddressLookupTable::deserialize(lookup_table_data)?;
|
||||
@ -315,6 +306,15 @@ impl Processor {
|
||||
|
||||
let table_key = *lookup_table_account.unsigned_key();
|
||||
if required_lamports > 0 {
|
||||
let payer_account =
|
||||
keyed_account_at_index(keyed_accounts, checked_add(first_instruction_account, 2)?)?;
|
||||
let payer_key = if let Some(payer_key) = payer_account.signer_key() {
|
||||
*payer_key
|
||||
} else {
|
||||
ic_msg!(invoke_context, "Payer account must be a signer");
|
||||
return Err(InstructionError::MissingRequiredSignature);
|
||||
};
|
||||
|
||||
invoke_context.native_invoke(
|
||||
system_instruction::transfer(&payer_key, &table_key, required_lamports),
|
||||
&[payer_key],
|
||||
|
Reference in New Issue
Block a user