here is my on-chain code to create the PDA account
#[derive(Accounts)]
pub struct Initialize<'info> {
#[account(init, payer = user, space = 20 , seeds = [user.key().as_ref()], bump)]
pub pda: Account<'info, MyData>,
#[account(mut)]
pub user: Signer<'info>,
pub system_program: Program<'info, System>,
}
the data inside:
#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
pub struct MyData {
pub userkey = Pubkey,
}
In my rust client code, can I get the data for "userkey" without deserializing? right now I'm doing
let account = connection.get_account(*PDA ADDRESS*).unwrap();
let data = &account.data;
let stored_key: String = Pubkey::new_from_array(data[10..42].try_into().unwrap()).to_string();
which is honestly super tedious and if I were to add more fields, id have to find the exact spot of the byte array again :(
I know that there is a .fetch() in javascript that lets me do this: let acc_info = await program.account.myData.fetch(PDA);
and then I can just get acc_info.userkey;
. is there a similar function in anchor_client?