Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions projects/challenge/smart_contracts/counter/contract.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# pyright: reportMissingModuleSource=false
from algopy import ARC4Contract, LocalState, GlobalState, UInt64, Txn, arc4, Global


class Counter(ARC4Contract):

count: LocalState[UInt64]
counters: GlobalState[UInt64]
def __init__(self) -> None:
self.count = LocalState(UInt64)
self.counters = GlobalState(UInt64(0))

@arc4.baremethod(allow_actions=["OptIn"])
def opt_in(self) -> None:
self.count[Txn.sender] = UInt64(0)
self.counters.value += 1

@arc4.abimethod()
def increment(self) -> arc4.UInt64:
assert Txn.sender.is_opted_in(
Global.current_application_id
), "Sender must opt-in to the contract"
self.count[Txn.sender] += 1
return arc4.UInt64(self.count[Txn.sender])