在 project-serum/anchor repo 的 Basic-5 教程中,如何将 #[related] 替换为以下内容:
#[account(seeds = [user_data.deposit_last.as_ref(), &[user_data.__nonce]])]
上面有一些不正确的地方,那么 Anchor 无法读取关联帐户的值
const userData = await program.account.userData.associated(wallet1, usdcMint);
那么在关联帐户结构上方替换这个即将被弃用的#[关联] 的正确方法是什么?
#[associated]
#[derive(Default)]
pub struct UserData {
pub authority: Pubkey,
pub deposit_last: i64,
pub shares: u64,
pub reward_debt: u64,
}
//UserData is initialized here first
#[derive(Accounts)]
pub struct Initialize<'info> {
#[account(init, associated = authority, with = usdc_mint)]
pub user_data: ProgramAccount<'info, UserData>,
...
}