lib.rs 1001 B

1234567891011121314151617181920212223242526272829303132
  1. #![allow(clippy::result_large_err)]
  2. use anchor_lang::prelude::*;
  3. declare_id!("ECWPhR3rJbaPfyNFgphnjxSEexbTArc7vxD8fnW6tgKw");
  4. #[program]
  5. pub mod anchor_program_example {
  6. use super::*;
  7. pub fn check_accounts(_ctx: Context<CheckingAccounts>) -> Result<()> {
  8. Ok(())
  9. }
  10. }
  11. // Account validation in Anchor is done using the types and constraints specified in the #[derive(Accounts)] structs
  12. // This is a simple example and does not include all possible constraints and types
  13. #[derive(Accounts)]
  14. pub struct CheckingAccounts<'info> {
  15. payer: Signer<'info>, // checks account is signer
  16. /// CHECK: No checks performed, example of an unchecked account
  17. #[account(mut)]
  18. account_to_create: UncheckedAccount<'info>,
  19. /// CHECK: Perform owner check using constraint
  20. #[account(
  21. mut,
  22. owner = id()
  23. )]
  24. account_to_change: UncheckedAccount<'info>,
  25. system_program: Program<'info, System>, // checks account is executable, and is the system program
  26. }