I’m trying to find an example that does it.
It seems all of the PDAs examples that I’ve seen so far have addresses and related account information generated off chain and then extracted in the list of accounts in the program as such:
let mut accounts_iter = accounts.iter();
let funder = next_account_info(&mut accounts_iter)?;
let account_to_init = next_account_info(&mut accounts_iter)?;
But then there is this function, which seems like it can find a valid PDA on-chan even if it means more calculation.
let (pda, bump) = Pubkey::find_program_address(&[seed.as_bytes()], program_id);
Just not really sure how to proceed with the pda
from above as the invoke_signed
function requires an AccountInfo
struct rather than solely the public key of the PDA.
In the hello-world counter example there is a test that has following code:
let program_id = Pubkey::default();
let key = Pubkey::default();
let mut lamports = 0;
let mut data = vec![0; mem::size_of::<u32>()];
let owner = Pubkey::default();
let account = AccountInfo::new(
&key,
false,
true,
&mut lamports,
&mut data,
&owner,
false,
Epoch::default(),
);
Is this how you would instantiate an AccountInfo
struct so that it could be signed and submitted with invoke_sign
on chain?
I know this is a bit of a niche question since every single example extracts account that are passed to it and those either already exist somewhere or have been assembled and serialised in the frontend.
Thanks for help