From 78e187f220c6ba9ca7c76476a6b58d0cbbd8caf2 Mon Sep 17 00:00:00 2001 From: Joe C Date: Fri, 16 Feb 2024 13:00:50 -0700 Subject: [PATCH] bpf-loader-upgradeable: export `get_program_data_address` helper (#35131) --- sdk/program/src/bpf_loader_upgradeable.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sdk/program/src/bpf_loader_upgradeable.rs b/sdk/program/src/bpf_loader_upgradeable.rs index 907a953d026706..40610f1c299637 100644 --- a/sdk/program/src/bpf_loader_upgradeable.rs +++ b/sdk/program/src/bpf_loader_upgradeable.rs @@ -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, @@ -175,7 +180,7 @@ pub fn deploy_with_max_program_len( program_lamports: u64, max_data_len: usize, ) -> Result, 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, @@ -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, @@ -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), @@ -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), @@ -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),