@@ -6,6 +6,7 @@ def __init__(self) -> None:
66 self .max_attendees = algopy .UInt64 (30 )
77 self .asset_url = algopy .String ("ipfs://QmW5vERkgeJJtSY1YQdcWU6gsHCZCyLFtM1oT9uyy2WGm8" )
88 self .total_attendees = algopy .UInt64 (0 )
9+ self .box_map = algopy .BoxMap (algopy .Bytes , algopy .UInt64 )
910
1011 @algopy .arc4 .abimethod (create = "require" )
1112 def init (self , max_attendees : algopy .UInt64 ) -> None :
@@ -24,12 +25,70 @@ def confirm_attendance(self) -> None:
2425
2526 algopy .op .Box .put (algopy .Txn .sender .bytes , algopy .op .itob (minted_asset .id ))
2627
28+ @algopy .arc4 .abimethod ()
29+ def confirm_attendance_with_box (self ) -> None :
30+ assert self .total_attendees < self .max_attendees , "Max attendees reached"
31+
32+ minted_asset = self ._mint_poa (algopy .Txn .sender )
33+ self .total_attendees += 1
34+
35+ box = algopy .Box (algopy .UInt64 , key = algopy .Txn .sender .bytes )
36+ has_claimed = bool (box )
37+ assert not has_claimed , "Already claimed POA"
38+
39+ box .value = minted_asset .id
40+
41+ @algopy .arc4 .abimethod ()
42+ def confirm_attendance_with_box_ref (self ) -> None :
43+ assert self .total_attendees < self .max_attendees , "Max attendees reached"
44+
45+ minted_asset = self ._mint_poa (algopy .Txn .sender )
46+ self .total_attendees += 1
47+
48+ box_ref = algopy .BoxRef (key = algopy .Txn .sender .bytes )
49+ has_claimed = bool (box_ref )
50+ assert not has_claimed , "Already claimed POA"
51+
52+ box_ref .put (algopy .op .itob (minted_asset .id ))
53+
54+ @algopy .arc4 .abimethod ()
55+ def confirm_attendance_with_box_map (self ) -> None :
56+ assert self .total_attendees < self .max_attendees , "Max attendees reached"
57+
58+ minted_asset = self ._mint_poa (algopy .Txn .sender )
59+ self .total_attendees += 1
60+
61+ has_claimed = algopy .Txn .sender .bytes in self .box_map
62+ assert not has_claimed , "Already claimed POA"
63+
64+ self .box_map [algopy .Txn .sender .bytes ] = minted_asset .id
65+
2766 @algopy .arc4 .abimethod (readonly = True )
2867 def get_poa_id (self ) -> algopy .UInt64 :
2968 poa_id , exists = algopy .op .Box .get (algopy .Txn .sender .bytes )
3069 assert exists , "POA not found"
3170 return algopy .op .btoi (poa_id )
3271
72+ @algopy .arc4 .abimethod (readonly = True )
73+ def get_poa_id_with_box (self ) -> algopy .UInt64 :
74+ box = algopy .Box (algopy .UInt64 , key = algopy .Txn .sender .bytes )
75+ poa_id , exists = box .maybe ()
76+ assert exists , "POA not found"
77+ return poa_id
78+
79+ @algopy .arc4 .abimethod (readonly = True )
80+ def get_poa_id_with_box_ref (self ) -> algopy .UInt64 :
81+ box_ref = algopy .BoxRef (key = algopy .Txn .sender .bytes )
82+ poa_id , exists = box_ref .maybe ()
83+ assert exists , "POA not found"
84+ return algopy .op .btoi (poa_id )
85+
86+ @algopy .arc4 .abimethod (readonly = True )
87+ def get_poa_id_with_box_map (self ) -> algopy .UInt64 :
88+ poa_id , exists = self .box_map .maybe (algopy .Txn .sender .bytes )
89+ assert exists , "POA not found"
90+ return poa_id
91+
3392 @algopy .arc4 .abimethod ()
3493 def claim_poa (self , opt_in_txn : algopy .gtxn .AssetTransferTransaction ) -> None :
3594 poa_id , exists = algopy .op .Box .get (algopy .Txn .sender .bytes )
@@ -49,6 +108,65 @@ def claim_poa(self, opt_in_txn: algopy.gtxn.AssetTransferTransaction) -> None:
49108 algopy .op .btoi (poa_id ),
50109 )
51110
111+ @algopy .arc4 .abimethod ()
112+ def claim_poa_with_box (self , opt_in_txn : algopy .gtxn .AssetTransferTransaction ) -> None :
113+ box = algopy .Box (algopy .UInt64 , key = algopy .Txn .sender .bytes )
114+ poa_id , exists = box .maybe ()
115+ assert exists , "POA not found, attendance validation failed!"
116+ assert opt_in_txn .xfer_asset .id == poa_id , "POA ID mismatch"
117+ assert opt_in_txn .fee == algopy .UInt64 (0 ), "We got you covered for free!"
118+ assert opt_in_txn .asset_amount == algopy .UInt64 (0 )
119+ assert (
120+ opt_in_txn .sender == opt_in_txn .asset_receiver == algopy .Txn .sender
121+ ), "Opt-in transaction sender and receiver must be the same"
122+ assert (
123+ opt_in_txn .asset_close_to == opt_in_txn .rekey_to == algopy .Global .zero_address
124+ ), "Opt-in transaction close to must be zero address"
125+
126+ self ._send_poa (
127+ algopy .Txn .sender ,
128+ poa_id ,
129+ )
130+
131+ @algopy .arc4 .abimethod ()
132+ def claim_poa_with_box_ref (self , opt_in_txn : algopy .gtxn .AssetTransferTransaction ) -> None :
133+ box_ref = algopy .BoxRef (key = algopy .Txn .sender .bytes )
134+ poa_id , exists = box_ref .maybe ()
135+ assert exists , "POA not found, attendance validation failed!"
136+ assert opt_in_txn .xfer_asset .id == algopy .op .btoi (poa_id ), "POA ID mismatch"
137+ assert opt_in_txn .fee == algopy .UInt64 (0 ), "We got you covered for free!"
138+ assert opt_in_txn .asset_amount == algopy .UInt64 (0 )
139+ assert (
140+ opt_in_txn .sender == opt_in_txn .asset_receiver == algopy .Txn .sender
141+ ), "Opt-in transaction sender and receiver must be the same"
142+ assert (
143+ opt_in_txn .asset_close_to == opt_in_txn .rekey_to == algopy .Global .zero_address
144+ ), "Opt-in transaction close to must be zero address"
145+
146+ self ._send_poa (
147+ algopy .Txn .sender ,
148+ algopy .op .btoi (poa_id ),
149+ )
150+
151+ @algopy .arc4 .abimethod ()
152+ def claim_poa_with_box_map (self , opt_in_txn : algopy .gtxn .AssetTransferTransaction ) -> None :
153+ poa_id , exists = self .box_map .maybe (algopy .Txn .sender .bytes )
154+ assert exists , "POA not found, attendance validation failed!"
155+ assert opt_in_txn .xfer_asset .id == poa_id , "POA ID mismatch"
156+ assert opt_in_txn .fee == algopy .UInt64 (0 ), "We got you covered for free!"
157+ assert opt_in_txn .asset_amount == algopy .UInt64 (0 )
158+ assert (
159+ opt_in_txn .sender == opt_in_txn .asset_receiver == algopy .Txn .sender
160+ ), "Opt-in transaction sender and receiver must be the same"
161+ assert (
162+ opt_in_txn .asset_close_to == opt_in_txn .rekey_to == algopy .Global .zero_address
163+ ), "Opt-in transaction close to must be zero address"
164+
165+ self ._send_poa (
166+ algopy .Txn .sender ,
167+ poa_id ,
168+ )
169+
52170 @algopy .subroutine
53171 def _mint_poa (self , claimer : algopy .Account ) -> algopy .Asset :
54172 algopy .ensure_budget (algopy .UInt64 (10000 ), algopy .OpUpFeeSource .AppAccount )
0 commit comments