-
Notifications
You must be signed in to change notification settings - Fork 2
/
counter.py
34 lines (27 loc) · 801 Bytes
/
counter.py
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
# Built with Seahorse v0.2.4
#
# On-chain, persistent Counter!
from seahorse.prelude import *
declare_id('C8ZXZXQuCKidMC1bjQduPjvSmkZqTBXukZbVxmGc9JAR')
class Counter(Account):
count: u64
user: Pubkey
@instruction
def create(counter: Empty[Counter], user: Signer):
counter = counter.init(
payer=user,
seeds=["counter", user]
)
counter.user = user.key()
@instruction
def reset(user: Signer, counter: Counter):
assert user.key() == counter.user, "Unauthorized"
counter.count = 0
@instruction
def increment(user: Signer, counter: Counter):
assert user.key() == counter.user, "Unauthorized"
counter.count += 1
@instruction
def decrement(user: Signer, counter: Counter):
assert user.key() == counter.user, "Unauthorized"
counter.count -= 1