lib.rs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. use anchor_lang::prelude::*;
  2. declare_id!("Re1ationsDerivation111111111111111111111111");
  3. #[program]
  4. pub mod relations_derivation {
  5. use super::*;
  6. pub fn init_base(ctx: Context<InitBase>) -> Result<()> {
  7. ctx.accounts.account.my_account = ctx.accounts.my_account.key();
  8. ctx.accounts.account.bump = ctx.bumps["account"];
  9. Ok(())
  10. }
  11. pub fn test_relation(_ctx: Context<TestRelation>) -> Result<()> {
  12. Ok(())
  13. }
  14. }
  15. #[derive(Accounts)]
  16. pub struct InitBase<'info> {
  17. /// CHECK: yeah I know
  18. #[account(mut)]
  19. my_account: Signer<'info>,
  20. #[account(
  21. init,
  22. payer = my_account,
  23. seeds = [b"seed"],
  24. space = 100,
  25. bump,
  26. )]
  27. account: Account<'info, MyAccount>,
  28. system_program: Program<'info, System>,
  29. }
  30. #[derive(Accounts)]
  31. pub struct Nested<'info> {
  32. /// CHECK: yeah I know
  33. my_account: UncheckedAccount<'info>,
  34. #[account(
  35. has_one = my_account,
  36. seeds = [b"seed"],
  37. bump = account.bump
  38. )]
  39. account: Account<'info, MyAccount>,
  40. }
  41. #[derive(Accounts)]
  42. pub struct TestRelation<'info> {
  43. /// CHECK: yeah I know
  44. my_account: UncheckedAccount<'info>,
  45. #[account(
  46. has_one = my_account,
  47. seeds = [b"seed"],
  48. bump = account.bump
  49. )]
  50. account: Account<'info, MyAccount>,
  51. nested: Nested<'info>,
  52. }
  53. #[account]
  54. pub struct MyAccount {
  55. pub my_account: Pubkey,
  56. pub bump: u8,
  57. }