Repository navigation
Expand file tree
/
Copy pathcounter_prize.teal
More file actions
96 lines (89 loc) · 1.84 KB
/
Copy pathcounter_prize.teal
File metadata and controls
96 lines (89 loc) · 1.84 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#pragma version 8
// ApplicationID will be 0 when the app is being created
// if Txn.ApplicationID == 0:
txn ApplicationID
pushint 0
==
bz l0_end
// then:
// Initialise the counter state to 0
// app_global_put("counter", 0)
pushbytes "counter"
pushint 0
app_global_put
// exit(1)
pushint 1
return
l0_end: // end
// if Txn.OnCompletion == UpdateApplication:
txn OnCompletion
pushint 4 // UpdateApplication
==
bz l1_end
// then:
// Only allow the Creator to update the app
// assert(Txn.Sender == Global.CreatorAddress)
txn Sender
global CreatorAddress
==
assert
// exit(1)
pushint 1
return
l1_end: // end
// Ensure that this is a NoOp application call. Don't allow optin, delete, etc
// assert(Txn.OnCompletion == NoOp)
txn OnCompletion
pushint 0 // NoOp
==
assert
// Read the counter value from state and increment it
// int counter = app_global_get("counter") [slot 0]
pushbytes "counter"
app_global_get
store 0 // counter
// counter = counter + 1
load 0 // counter
pushint 1
+
store 0 // counter
// app_global_put("counter", counter)
pushbytes "counter"
load 0 // counter
app_global_put
// if counter == 10:
load 0 // counter
pushint 10
==
bz l2_elif_0
// then:
// If the counter is 10 make a Payment transaction
// inner_txn:
itxn_begin
// TypeEnum: Pay
pushint 1 // Pay
itxn_field TypeEnum
// Receiver: Txn.Sender
txn Sender
itxn_field Receiver
// Amount: 10000000
pushint 10000000
itxn_field Amount
itxn_submit
// end inner_txn
b l2_end
l2_elif_0:
// elif counter > 10:
load 0 // counter
pushint 10
>
bz l2_end
// If the counter is past 10 fail the program
// exit(0)
pushint 0
return
l2_end: // end
// Exit the program with approval
// exit(1)
pushint 1
return