Skip to content

Commit

Permalink
find_pda (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
billythedummy authored Sep 13, 2024
1 parent bda9f30 commit 5a32edb
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions sdk/src/pubkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,21 @@ pub fn log_pubkey(pubkey: &Pubkey) {
#[cfg(not(target_os = "solana"))]
core::hint::black_box(pubkey);
}

pub fn find_program_address(seeds: &[&[u8]], program_id: &Pubkey) -> (Pubkey, u8) {
let mut bytes = [0; 32];
let mut bump_seed = u8::MAX;
let result = unsafe {
crate::syscalls::sol_try_find_program_address(
seeds as *const _ as *const u8,
seeds.len() as u64,
program_id as *const _ as *const u8,
&mut bytes as *mut _ as *mut u8,
&mut bump_seed as *mut _,
)
};
match result {
crate::entrypoint::SUCCESS => (bytes, bump_seed),
_ => panic!("PDA cannot be found"),
}
}

0 comments on commit 5a32edb

Please sign in to comment.