Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpf-loader-upgradeable: export get_program_data_address helper #35131

Merged
merged 1 commit into from
Feb 16, 2024
Merged
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
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
Loading