-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
lib.rs
44 lines (37 loc) · 978 Bytes
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// #region code
use anchor_lang::prelude::*;
declare_id!("CwrqeMj2U8tFr1Rhkgwc84tpAsqbt9pTt2a4taoTADPr");
#[program]
pub mod basic_4 {
use super::*;
#[state]
pub struct Counter {
pub authority: Pubkey,
pub count: u64,
}
impl Counter {
pub fn new(ctx: Context<Auth>) -> anchor_lang::Result<Self> {
Ok(Self {
authority: *ctx.accounts.authority.key,
count: 0,
})
}
pub fn increment(&mut self, ctx: Context<Auth>) -> anchor_lang::Result<()> {
if &self.authority != ctx.accounts.authority.key {
return Err(error!(ErrorCode::Unauthorized));
}
self.count += 1;
Ok(())
}
}
}
#[derive(Accounts)]
pub struct Auth<'info> {
authority: Signer<'info>,
}
// #endregion code
#[error_code]
pub enum ErrorCode {
#[msg("You are not authorized to perform this action.")]
Unauthorized,
}