Skip to content

Commit

Permalink
bpf-loader-upgradeable: export get_program_data_address helper (#35131
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Joe C authored Feb 16, 2024
1 parent 2a9ed3e commit 78e187f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions sdk/program/src/bpf_loader_upgradeable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ impl UpgradeableLoaderState {
}
}

/// Returns the program data address for a program ID
pub fn get_program_data_address(program_address: &Pubkey) -> Pubkey {
Pubkey::find_program_address(&[program_address.as_ref()], &id()).0
}

/// Returns the instructions required to initialize a Buffer account.
pub fn create_buffer(
payer_address: &Pubkey,
Expand Down Expand Up @@ -175,7 +180,7 @@ pub fn deploy_with_max_program_len(
program_lamports: u64,
max_data_len: usize,
) -> Result<Vec<Instruction>, InstructionError> {
let (programdata_address, _) = Pubkey::find_program_address(&[program_address.as_ref()], &id());
let programdata_address = get_program_data_address(program_address);
Ok(vec![
system_instruction::create_account(
payer_address,
Expand Down Expand Up @@ -208,7 +213,7 @@ pub fn upgrade(
authority_address: &Pubkey,
spill_address: &Pubkey,
) -> Instruction {
let (programdata_address, _) = Pubkey::find_program_address(&[program_address.as_ref()], &id());
let programdata_address = get_program_data_address(program_address);
Instruction::new_with_bincode(
id(),
&UpgradeableLoaderInstruction::Upgrade,
Expand Down Expand Up @@ -281,7 +286,7 @@ pub fn set_upgrade_authority(
current_authority_address: &Pubkey,
new_authority_address: Option<&Pubkey>,
) -> Instruction {
let (programdata_address, _) = Pubkey::find_program_address(&[program_address.as_ref()], &id());
let programdata_address = get_program_data_address(program_address);

let mut metas = vec![
AccountMeta::new(programdata_address, false),
Expand All @@ -300,7 +305,7 @@ pub fn set_upgrade_authority_checked(
current_authority_address: &Pubkey,
new_authority_address: &Pubkey,
) -> Instruction {
let (programdata_address, _) = Pubkey::find_program_address(&[program_address.as_ref()], &id());
let programdata_address = get_program_data_address(program_address);

let metas = vec![
AccountMeta::new(programdata_address, false),
Expand Down Expand Up @@ -355,8 +360,7 @@ pub fn extend_program(
payer_address: Option<&Pubkey>,
additional_bytes: u32,
) -> Instruction {
let (program_data_address, _) =
Pubkey::find_program_address(&[program_address.as_ref()], &id());
let program_data_address = get_program_data_address(program_address);
let mut metas = vec![
AccountMeta::new(program_data_address, false),
AccountMeta::new(*program_address, false),
Expand Down

0 comments on commit 78e187f

Please sign in to comment.