lib.rs 939 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. use anchor_lang::prelude::*;
  2. declare_id!("Externa111111111111111111111111111111111111");
  3. #[program]
  4. pub mod external {
  5. use super::*;
  6. pub fn init(_ctx: Context<Init>) -> Result<()> {
  7. Ok(())
  8. }
  9. pub fn update(ctx: Context<Update>, value: u32) -> Result<()> {
  10. ctx.accounts.my_account.field = value;
  11. Ok(())
  12. }
  13. }
  14. #[derive(Accounts)]
  15. pub struct Init<'info> {
  16. #[account(mut)]
  17. pub authority: Signer<'info>,
  18. #[account(
  19. init,
  20. payer = authority,
  21. space = 8 + 4,
  22. seeds = [authority.key.as_ref()],
  23. bump
  24. )]
  25. pub my_account: Account<'info, MyAccount>,
  26. pub system_program: Program<'info, System>,
  27. }
  28. #[derive(Accounts)]
  29. pub struct Update<'info> {
  30. pub authority: Signer<'info>,
  31. #[account(mut, seeds = [authority.key.as_ref()], bump)]
  32. pub my_account: Account<'info, MyAccount>,
  33. }
  34. #[account]
  35. pub struct MyAccount {
  36. pub field: u32,
  37. }